我想为我的所有博客页面(首页/单个帖子/存档(标签,作者,类别等))指定特定的标题。
我设法将博客的首页作为目标,但其余部分(单个/存档)却没有:
function add_blog_header_single() {
// Echo out content
if ( is_home() && !is_front_page() ) {
echo
'<div id="blog-header"><p>
<img src="img.png" alt="">
</p></div>'
;
}
}
add_action( 'storefront_content_top' , 'add_blog_header_single', 20 );
我该怎么办?
谢谢
答案 0 :(得分:0)
在这里,将此代码添加到主题functions.php文件中。
function add_blog_header_single() {
$img_src = 'default-image.png'
if ( is_home() ) { // When the main blog page is being displayed.
$img_src = 'blog.png';
}
if( is_single() ) { // When a single post of any post type (except attachment and page post types) is being displayed.
$img_src = 'single-post.png';
}
if( is_archive() ) { // When any type of Archive page is being displayed. Category, Tag, other Taxonomy Term, custom post type archive, Author and Date-based pages are all types of Archives.
$img_src = 'archive.png';
}
echo '<div id="blog-header"><p> <img src="'.$img_src.'" alt=""></p></div>';
}
add_action( 'storefront_content_top' , 'add_blog_header_single', 20 );