has_header_image()判断当前主题是否设置了头部图像

目录

描述

Check whether a header image for the current theme is set or not.

has_header_image() 描述

用法

<?php has_header_image() ?>

has_header_image() 用法

参数

None.

has_header_image() 参数

返回值

(bool) 

Returns true if a header image has been set, otherwise false if:

  • The current theme does NOT support header images. (Learn how to enable it in Custom Headers page).
  • The current theme DOES support header images. However, the user has selected the "Remove Header Image" option from the Appearance -> Header screen.

has_header_image() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<?php if ( has_header_image() ) { ?>
<img src="<?php echo( get_header_image() ); ?>" alt="<?php echo( get_bloginfo( 'title' ) ); ?>" />
<?php } ?>

has_header_image() 示例

历史

添加于 版本: 4.2.0

has_header_image() 历史

源文件

has_header_image() 函数的代码位于 wp-includes/theme.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Check whether a header image is set or not.
 *
 * @since 4.2.0
 *
 * @see get_header_image()
 *
 * @return bool Whether a header image is set or not.
 */
function has_header_image() {
	return (bool) get_header_image();
}

has_header_image() 源文件