It should be enough using a single <span>
for all categories and add some logic.:
<span><?php
$categories = ['horses','dogs','birds'];
$string = "";
foreach ($categories as $category){ //iterate over the categories to check
if(has_category($category))
$string .= $category.", "; //if in_category add to the output
}
$string = trim($string); //remove extra space from end
$string = rtrim($string, ','); //remove extra comma from end
echo $string; //result example: <span>horses, dogs</span>
?></span>
Related Posts:
- List all subcategories from category
- Get category ID from category slug (not working)
- How do I remove “Uncategorized” from posts with more than 1 category?
- Remove parent category from permalink? Basically only have the child category?
- Control term order on a per-post basis
- Filter by post category in Media Library
- Get page content by category or tag
- Using categories & “stickyness” together
- Changing the category permalink structure
- Display WooCommerce product categories in a 4 columns custom menu [closed]
- Page with the same name of a category
- How to make category RSS feeds show full content
- How to Check if a Child Category is Being Queried
- Creating Pages that show specific blog categories [closed]
- If a post belongs to two categories how do I choose the main category?
- Change post category based on latest posts views
- Attachment page per category
- How to get the depth of a category’s subcategories
- Best way to programmatically link to multiple categories (union/intersection) [closed]
- in_category() works in single.php but not in page.php?
- functions.php conditional tag – only show in single.php?
- How do I create a way for users to assign categories to a post from the frontend of the website?
- Get categories from save_post hook
- Need to pull parent category and slug – only pulling daughter category
- Is it possible to restrict viewing of category PAGE to logged in users only?
- Display children of the category a post is assigned to
- Random post + categories + tags
- how to define category loop last class in the third
- Making the category & tag Description textarea bigger
- WordPress category page redirects in .htaccess not working
- WordPress admin categories sort show is wrong
- Huge category CSV import does not work
- Needing a snippet for listing category specific tags
- Displaying Categories and Sub Categories
- Change thumbnail image depending product category
- How to organize custom categories for filtering and selecting
- How to list categories within tags?
- get_next_post set the category
- WordPress URL Rewrite for dynamic and customized URL
- Different menu navigation per category
- category doesn’t showing up in admin
- How to hide category name
- Get category URL knowing it’s id
- Keyword search in multiple categories
- Targeting Parent Category Pages
- Change every post background based on category
- How could I know all the categories from post?
- How to make subcategory for custom post and and display?
- Create menu locations for each category in wordpress
- Get category’s parent category while using get_the_category_list
- How to make the ‘delete’ button inactive on some categories?
- Linking doctors posts to specific services for a medical practice
- Array: What is this value based on?
- How to show the category of custom taxonomy
- Show testimonials based on post category matching product name
- WordPress list categories dropdown with parent-child relation and child under it’s parent
- How to Link to Most Recent Custom Post of Same Term
- Remove parent category from child/sub-category page URL in WordPress
- Category page not showing
- Showing HTML if Post is In Certain Taxonomy Term
- Add code to header based on category for specific posts?
- How to only show parent categories in sidebar
- Change RSS format for specific categories
- Can I prioritize post categories for choice for breadcrumb trail?
- Displaying a custom field in Category Archives
- Category List with custom urls
- Custom Portfolio Page
- Custom Fields Value As Taxonomy
- Load the last post of a category
- create function to call category name and slug
- Redirect Problems with Archive Page and GET variables
- Different size video display for category page (smaller) & detail page (larger)
- Adding tinymce to Custom Field boxes on Category edit page
- Disable Category Taxonomy
- How do you get sticky posts to work with categories?
- A different permalink structure for different categories
- How to make product image inherit from category image
- Is it possible to set up blog categories without changing permalink structure
- How to display categories image in loop homepage WordPress
- Display the articles of a category by role
- Remove “Category:” from Post meta
- How to “remove” WordPress categories UL and make the list loop in a horizontal line?
- How do I rewrite a single category link to point to a custom page?
- Add subcategories posts to the counts column at the admin’s categories list
- Default category isn’t saved in database
- Display one post on category.php: Wrong featured image
- Display related posts with same category or same tag return blank
- Get posts from 2 or more categories
- Category foreach Paging
- date.php shows all posts. how to fix it?
- Help with Wp + Mixitup code
- One category not displaying template updates
- How to display only category of blog without custom code?
- Matching usermeta at registration to categories of content
- How do I hide posts in a category from all listings but still allow the posts to be viewed?
- How to get Woocomerce categories count
- show posts from some category and sort by advance custom field
- How to show monthly archive posts?
- How to display posts by author in a separate page, other than author.php?
- One color to category link depending on category ID