最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - how to make wordpress change the title and keep page name?

programmeradmin0浏览0评论

I want to change the title of my archive page from "category" to "department" to get something like this: Department: Marketing. Where "department" is the archive page title and "Marketing" is the actual name. This is the code that I used:

add_filter( 'get_the_archive_title', function ( $title ) {

    if( is_category() ) {

        $title = 'department';

    }

    return $title;

});

But It hides the page name. When I use this code, I get only "Department" as a title and when I delete it, I get "category: department".

How to fix it?

I want to change the title of my archive page from "category" to "department" to get something like this: Department: Marketing. Where "department" is the archive page title and "Marketing" is the actual name. This is the code that I used:

add_filter( 'get_the_archive_title', function ( $title ) {

    if( is_category() ) {

        $title = 'department';

    }

    return $title;

});

But It hides the page name. When I use this code, I get only "Department" as a title and when I delete it, I get "category: department".

How to fix it?

Share Improve this question asked Jan 12, 2021 at 0:58 josephjoseph 135 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You need to add the actual page title back in. Try this:

add_filter( 'get_the_archive_title', function ( $title ) {
    if( is_category() ) {
        $title = 'Department: '. single_cat_title( '', false );
    }
    return $title;
});
发布评论

评论列表(0)

  1. 暂无评论