我认为自定义图像头有一个条件,可以检查是否添加了图像(不是该功能是否已启用,而是实际正在使用)。我想用它来添加body类,但我再也找不到了。有人知道如何检查站点是否有自定义标题吗?
有条件的自定义图像标题
1 个回复
最合适的回答,由SO网友:WP Themes 整理而成
在调用body_class()
功能:
<?php
$header_image = get_header_image();
if( !empty( $header_image) ){
$custom_body_class = \'has-header-image\';
} else {
$custom_body_class = \'no-header-image\';
}
?>
<body <?php body_class($custom_body_class); ?>>
结束