我正在为wordpress主题目录开发一个wordpress主题。在这个主题中,我通过这个波纹管在函数上设置了一个自定义标题图像.php
$defaults = array(
'width' => 1600,
'height' => 400,
'flex-height' => false,
'flex-width' => false,
'default-image' => get_template_directory_uri() . '/images/lemon.jpg',
'uploads' => true,
'default-text-color' => '95b849',
'header-text' => true,
);
add_theme_support( 'custom-header',$defaults);
我像下面一样显示这个标题图像:
<div class="header_top_image" style="background-image: url(<?php header_image(); ?>); background-color: #<?php echo get_header_textcolor();?>;">
<h1 class="header_top_title">
<a style="color: #<?php echo get_header_textcolor();?>;" href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php bloginfo('name'); ?>
</a>
</h1>
</div>
在这种情况下,我想要:如果没有设置自定义标题图像,这个"header_top_image"类的div 标签完全不显示。
我怎么能做到。其实我想,有一个函数:is_custome_header() ,甚至我在法典上搜索。但没有找到任何像这样的函数来提供 if 条件。有人可以帮助我吗?我非常需要这个解决方案。提前感谢
实际上现在我得到了解决方案。 它将:
<?php
if(get_header_image()){ ?>
<div>Desired div/elements here</div>
<?php } ?>