尝试在函数中添加默认图像标签.php但它不起作用。只有当我从 wp 仪表板上传 img 但默认 img 不起作用时,它才有效
functions.php
<?php
add_theme_support('title-tag');
add_theme_support('custom-header', array(
'default-image' => get_stylesheet_directory_uri() . '/images/logo.jpg',
));
?>
.CSS
#logo{
width: 890px;
position: relative;
height: 200px;
}
.HTML
<div id="logo" style="background: url(<?php header_image(); ?>) no-repeat;">
<div id="logo_text">
<!-- class="logo_colour", allows you to change the colour of the text -->
<h1><a href="index.html"><?php bloginfo('name');?></a></h1>
<h2><?php bloginfo('description');?></h2>
</div>
</div>
经过一番挖掘,我发现在子主题中添加默认图像路径是完全不同的。
保持这样的路径,它会起作用。
add_theme_support('custom-header', array(
'default-image' => '%2$s/images/logo.jpg',
));
在父主题中应使用%s
,而在子主题中应使用%2$s
。
请参阅本页中的示例。 https://codex.wordpress.org/Function_Reference/register_default_headers
您是否在 css 文件中添加了背景图像?
- 从函数中删除代码.php
- 将 html 代码设为
<div id="logo">
<div id="logo_text">
<!-- class="logo_colour", allows you to change the colour of the text -->
<h1><a href="index.html"><?php bloginfo('name');?></a></h1>
<h2><?php bloginfo('description');?></h2>
</div>
</div>
- 添加样式
#logo {
width: 890px;
position: relative;
height: 200px;
background-image:url('../images/logo.jpg');
}