To achieve this we need to use get_the_category
here.
I am going to use this code in several places, so it is more efficient to create a function
function exclude_cats($excludedcats = array()){ $categories = get_the_category(); $separator=", "; $output=""; foreach($categories as $category) { if ( !in_array($category->cat_ID, $excludedcats) ) { $output .= 'term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.''.$separator; } } echo trim($output, $separator); }
All that I’ve done inside the function was to call get_the_category
function, But I’ve excluded the categories I don’t want to show their names to not show.
inside the index I’ve called the function like so exclude_cats(array(11, 40, 53));
Related Posts:
- WordPress Multisite – global categories
- Get posts from sites in Multisite?
- Retrieve Product category ‘NAME’ by product category ID – WooCommerce?
- Can’t custom taxonomies have same terms (slugs) as categories?
- Using wp_category_checklist in a widget
- Filter front page posts by category
- How to get the url to tag & category base set by the user?
- Exclude one category from get_the_term_list
- WordPress remove separator from last item in wp_list_categories
- Filter categories using tags
- Need help adding custom field to category
- Get id of category from drop down menu
- How can I only show certain posts?
- Category menu item and its last 10 posts as sub-menu
- what is the action hook code to supporting product category condition in single product page of woocommerce?
- Prevent function from triggering again when post in specific category gets another category?
- Posts from multiblt categories but featured image only in the first one, the rest to have the post title only
- Conditional Tag for sub cagtegories?
- Display only posts from referred category on date archive page
- Sort post’s categories by ID
- Add a wordpress blog to my website having users
- in_category() not working in WordPress 4.9.7
- Set the default category of an attachment
- exclude post from displaying in loop if it is in a category, but not in many categories
- Show Featured products in product category pages
- How to remove category titles?
- Inserting Category programmatically
- Category-slug.php not being used
- Get only one of the current categories
- Show Available Taxonomy List with Current Category
- How to get grandparent of a given category
- Additional form options based on category selected not working
- Pagination for category slug returns 404 when page >= 2
- Display category-specific comments in sidebar
- Why does the argument list_only do on Walker_Category_Checklist::start_el?
- Paging not working in category.php
- Create menu / submenu from category subcategory and posts
- Display list of categories filtered by date?
- Remove the parent name from permalink
- Make parent category an optgroup
- Redirect single article permalink to paginated category page
- Exclude category by slug in pre_get_posts?
- add slug beside name in Admin Category Checklists
- How to show 5 posts from specific category on related page?
- List only categories i specify
- Author Page – List of categories plus number of posts in that category
- Exclude category from related post
- On the Blogpost I have categories showing, is there a way to exclude a catgegory like ‘Media’?
- How can you access category information from a theme?
- Set category page title in custom theme [closed]
- Filter WooCommerce archive pages by an additional category
- Posts from a category on homepage with category archieves page default css
- How to use wp_list_categories with plugin category?
- Theme modification for custom category menus
- Custom css per category and per single post belong in each category
- How Do I Delete WordPress Posts Older Than 400 Days, From A WordPress Category
- Category Page Template – Can’t get category ID
- wordpress taxonomy query posts
- Filter Category Loop Dynamically
- Subcategory is displayed before Parent Category
- Shortcode to display all the post from a category in a page
- How to display WooCommerce category image in my category page banner as a background?
- Order wp_dropdown_categories by ASC or DESC
- Custom Loop with certain number of one category
- “Special” category is displayed in all categories or show parent category on sub category
- How to list all subcategories from all categories but not from a certain category
- add woocommerce archive description if exist
- Can’t display posts by filtering categories using isotope.js
- Get a list of categories, separated by / to display inside the for custom metatags
- Automatically create tags and merge with categories
- Is there a reason to put a product in both the Child and Parent Categories?
- Get_term_meta() always returns false
- How to list all categories a post is in, but exclude current post´s category on single post page
- Get only children category name
- Displaying only selected categories
- No results found for second level category
- get_the_category vs wp_get_post_categories
- How to get get_categories()’s ‘hide_empty’ argument to work with global year var in the archive template?
- Getting a sub category based on a category name
- I have many different products on my website how can I get them to display under specific categories?
- Help with SQL query, how to add taxonomie terms with value stored in options?
- Categories in media library
- WordPress Shop and restricting products and categories for some users/groups
- Pass list of categories to JS
- WP url to get rss with full text of post
- Display Referring Category on single post?
- WP_query exclude a category unless it has more than one catagory
- Paginating a list of all posts collected by category titles
- Display deepest post category, when post have multiple categories
- Paginate WordPress Category Pages
- Get a list of post titles and links from yootheme master theme
- Customize category query in widget
- Page permalink rewrite
- How to control order when displaying child categories
- Broken category styling
- Trying to WP_Query a category
- Woocommerce Force the category choice before creating new product? [duplicate]
- hide_empty property not working when using get_terms
- sub-category showing up in wrong order in breadcrumbs
- Hierarchical outline of posts