Hide a certain category name without removing it?
Hi,
I have a category called feature which I use to have a feature post on the homepage. The problem is I don't want the category name feature to appear in this posts, but I want the other categories to show up.
I use Blocksy Theme Premium, Brizy Builder Pro, and I tried this code:
add_filter('get_the_terms', 'hide_categories_terms', 10, 3);
function hide_categories_terms($terms, $post_id, $taxonomy){
// define which category IDs you want to hide
$excludeIDs = array(6);
// get all the terms
$exclude = array();
foreach ($excludeIDs as $id) {
$exclude[] = get_term_by('id', $id, 'category');
}
// filter the categories
if (!is_admin()) {
foreach($terms as $key => $term){
if($term->taxonomy == "category"){
foreach ($exclude as $exKey => $exTerm) {
if($term->term_id == $exTerm->term_id) unset($terms[$key]);
}
}
}
}
return $terms;
}
...And on the Blocksy post pages it's work perfectly, but on post pages a made with Brizy Page Builder doesn't work.
Can u tell me how to solve this problem?
-
Hi,
where exactly do you want to hide this category? Do you want posts from this category not to appear on the Blog page? Is the blog page created with Brizy Template?
0 -
Hi Alex,
Do you want posts from this category not to appear on the Blog page? No.I just want to hide the category name, and the posts to stay ...The reason for that is that I have the positioning of some posts. For example, I have positions A, B, C, D, and I want a post to be in position "A", but at the same time I want that post to be shown to me in the "Sports" category.
0 -
ok I understand. Unfortunately, I can't help you with a custom code that will solve your problem. But if you say you just want to hide the category name then you can try Custom CSS. You can use: nth-child() to hide the category name from certain pages thus there will be no link to this category.
0 -
Okay.
But why Brizy is not compatible with my code?
It works perfectly on archive posts created with the theme.
0 -
Unfortunately, I do not have an answer to this question. You need to inspect how Brizy extracts categories because it's a bit different from how default WordPress archives work. The support does not include these external works, so I'm afraid that as long as there are no options for this, any custom changes must be made at your own risk.
0
Please sign in to leave a comment.
Comments
5 comments