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

categories - How to hide category name

programmeradmin2浏览0评论

I have a category about the catalog, news1 Which I use to get a post on the main page. The problem is that I don't want the news1 category name to appear in these posts, but I want other categories to be displayed.

How can I do this?

I have a category about the catalog, news1 Which I use to get a post on the main page. The problem is that I don't want the news1 category name to appear in these posts, but I want other categories to be displayed.

How can I do this?

Share Improve this question edited Oct 23, 2019 at 6:10 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Oct 22, 2019 at 22:58 Hubert K-iHubert K-i 191 bronze badge 1
  • Welcome to WordPress Development. I hope you find the answer(s) you are looking for. Our site is different from most - if you have not done so yet, consider checking out the tour and help center to find out how things work. – Matthew Brown aka Lord Matt Commented Oct 22, 2019 at 23:06
Add a comment  | 

2 Answers 2

Reset to default 0

First of all, I wouldn't recommend to use categories to show posts anywhere. Such approach has many consequences (it creates category archive, feeds, and so on).

But if you already have such solution, then you can use get_the_categories filter and remove given category from the list.

add_filter( 'get_the_categories', function ( $categories, $id ) {
    foreach ( $categories as $i => $term ) {
        if ( <ID_OF_CATEGORY_TO_IGNORE> == $term->term_id ) {
            unset( $categories[$i] );
        }
    }
    return $categories;
}, 10, 2 );

Just make the category status "private". It should do the job and will not be visible publicly

发布评论

评论列表(0)

  1. 暂无评论