WordPress 函数 header_image()

header_image() 函数是 WordPress 自定顶部图像的标准接口函数,该函数可以自动判断后台设置,并返回字符串形式的用户自定义顶部图像地址。本文主要涉及该函数的详解及使用。

意义详解

【Display header image path.】 即,显示顶部图像地址。更高阶的东西请参阅 get_custom_header

使用

<img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />

函数声明源代码

function header_textcolor() {
	echo get_header_textcolor();
}
function get_header_image() {
	$url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) );
 
	if ( 'remove-header' == $url )
		return false;
 
	if ( is_random_header_image() )
		$url = get_random_header_image();
 
	if ( is_ssl() )
		$url = str_replace( 'http://', 'https://', $url );
	else
		$url = str_replace( 'https://', 'http://', $url );
 
	return esc_url_raw( $url );
}

总结

WordPress 经过近几年的发展,相较于最之前的版本,现在的的 WordPress 越来越容易上手了,因为频繁的更新,我还是建议您使用标准节接口进行主题开发。

原文来自http://pangbu.com/header_image/