首页 > 解决方案 > 向所有博客页面添加操作

问题描述

我想为我的所有博客页面(主页/单篇文章/存档(标签、作者、类别等)都有一个特定的标题。

我已经设法定位博客的主页,但不是其余的(单个/档案):

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 );

我应该怎么办 ?

谢谢

标签: wordpressfunctionstorefront

解决方案


在这里,在您的主题 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 );

推荐阅读