Changing the title of Wordpress Tag Pages

 ̄綄美尐妖づ 提交于 2019-12-11 10:36:42

问题


I wish to change the title of Tags pages of my wordpress blog. What I want to do is to keep the Tag name as it's title only.

For example: If a tag name is "Wordpress Tag Pages Tutorial" then that tag should have the same title "Wordpress Tag Pages Tutorial" instead of "Blog Name - Wordpress Tag Pages Tutorial" so what to change in this code? I have tried but showing errors like only variables name in wordpress title.

<title>
<?php if (is_home () ) { bloginfo('name'); }elseif ( is_category() ) {
single_cat_title(); echo ' - ' ; bloginfo('name'); }
elseif (is_single() ) { single_post_title();}
elseif (is_page() ) { bloginfo('name'); echo ': '; single_post_title();}
else { wp_title('',true); } ?>


回答1:


You're missing is_tag().

Example:

if ( is_tag() ) {
    $tag = single_tag_title("", false);
    echo $tag;
}



回答2:


If there are any SEO plugins installed in the site, it will override the 'wp_title' function. So you can manage the title string in that plugin settings.

If there are no such plugins, you can use following code:

    add_filter('wp_title', 'hs_tag_titles',10);

function hs_tag_titles($orig_title) {

    global $post;
    $tag_title = 'Test Title';
    if ( is_tag() ) {
        return $tag_title;
    } else {
        return $orig_title;
    }
}


来源:https://stackoverflow.com/questions/14049555/changing-the-title-of-wordpress-tag-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!