admin管理员组文章数量:1122846
I have a category called "Featured", but I don't want this category tag to be shown at the bottom of single post pages. I do want to display the other category tags. How do I hide the tag for this one category?
I have a category called "Featured", but I don't want this category tag to be shown at the bottom of single post pages. I do want to display the other category tags. How do I hide the tag for this one category?
Share Improve this question asked Feb 20, 2020 at 14:24 MrFoxMrFox 3042 gold badges7 silver badges19 bronze badges3 Answers
Reset to default 0For specifically post categories, you can use get_the_categories filter hook to remove certain found category (term).
function filter_get_the_category( $categories, $post_id ) {
// loop post categories
foreach ($categories as $index => $category) {
// check for certain category, you could also check for $term->slug or $term->term_id
if ( 'Featured' === $category->name ) {
// remove it from the array
unset( $categories[$index] );
}
}
return $categories;
}
add_filter( 'get_the_categories', 'filter_get_the_category', 10, 2 );
To filter any taxonomy terms, you can use get_the_terms hook.
function filter_get_the_terms( $terms, $post_id, $taxonomy ) {
// target certain taxonomy
if ( 'category' === $taxonomy && ! is_wp_error( $terms ) ) {
// loop found terms
foreach ($terms as $index => $term) {
// check for certain term, you could also check for $term->slug or $term->term_id
if ( 'Featured' === $term->name ) {
// remove it from the array
unset( $terms[$index] );
}
}
}
return $terms;
}
add_filter( 'get_the_terms', 'filter_get_the_terms', 10, 3 );
I've decided to go with this simple solution
if ( in_category('featured') ) {
}else{
entry_meta();
}
I tried to follow the code above but to no avail. How can i hide Company News categories when accessing posts related to CSR events category? Please see page link below: https://www.mi-eq.com/blood-donation-compaign/
本文标签: categoriesHide specific category tag on single post page
版权声明:本文标题:categories - Hide specific category tag on single post page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736291786a1928797.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论