You have to pass the values, not echo
them.
So something like this should work:
$post_cats = get_the_category();
$slugs = wp_list_pluck( $post_cats, 'slug' );
post_class( join( ' ', $slugs );
Related Posts:
- How can I make wp_list_categories output li with category-slug as class, for its children?
- How can i remove the posts category class names from body_class
- Get categories list with category name in custom WP_List_Table class
- post_class remove tag- or category- from slug
- Different styles for categories – need to edit a plugin
- Control term order on a per-post basis
- Display all posts from all categories with pagination
- is_category() function
- Changing Top Level Items into Radio Buttons in the Categories Meta Box?
- How to create a widgetized sidebar for every category dynamically?
- Display the deepest child category from Category X (in loop)
- Remove “Category Archives: title” at the top of a category page [duplicate]
- When using get_categories or similar, is it possible to filter results that contain certain Tags as well?
- Exclude subcategories from the url
- WooCommerce – Display product child categories from specific parent
- Select category in custom query
- Removed slug from CPT, now How/where do I hook the filter to the taxonomy term archive pages link?
- Display empty taxonomy terms with get_terms()
- Show list of categories even if they have no posts
- Search by word, category, tag, author
- How can I show the subcategories content on the parent category page?
- How to control template resolution if both Author and Category filter in place?
- Resolved – category-slug.php not working after wordpress migration
- How to retain the values from dropdown category lists after wrong form submission?
- Format Brand value in Category view [closed]
- Get multidimensional array that reflects category hierarchy
- Single_cat_title() print the title before text
- Sort posts by post_type in category.php template
- Add Post Screen Keep Category structure
- Possible to make a subdirectory that loops through a single category?
- editing fonts of category links from the_category() funtion
- Force a user’s posts category
- Archives for each category on WP Multisite
- Update post title with category name after editing a category
- Automatically set default password to all posts in a specific category
- Style wp_list_categories
- Checking for two categories in query_posts
- get_the_categories filter returns an empty array
- Warn me about ‘uncategorized’ posts
- Categories showing page not found
- Why category.php throw 404 in wordpress while calling paginate_links()?
- How to get related tags based on a category?
- Show category to visitors in different name or different language without changing basic category
- How to get latest posts from each category in regular order
- Pagination for ajax category filter
- Get posts from specific taxonomy term
- limit a list of tags to one category [closed]
- How many categories can WordPress handle before performance suffers?
- WordPress Drop down category as array for using in page builder
- Get sort order of product categories
- How to select category on if function
- how to wordpress When I click on the category link, subcategories appear
- Problem with different query loops (and “main loop”) on category template page!
- Show posts in “image” format when viewed in category page, but with comments in blog
- How to pull a list of posts in a category while exluding posts in subcategories of the category
- How to change the order of the subcategory and category in a post?
- Properly setting up a feed
- Display posts of certain categories to specific user roles
- Display Related Posts by “Category” “by Author”
- Change post title if post has specific category
- How to schedule categories?
- Template for product-category page [closed]
- How set all posts in wordpress in one category
- Copy post taxonomy?
- custom query for both category and pages using global $wpdb;
- url for posts for a date within a category
- How can I include custom category and tag base in template files?
- Category List with custom urls
- query_post problem
- Get a list of all links on a page?
- Load the last post of a category
- create function to call category name and slug
- Disable Category Taxonomy
- How to make product image inherit from category image
- Is this process OK to replace URL structure?
- Is it possible to set up blog categories without changing permalink structure
- How to display categories image in loop homepage WordPress
- how to give different template to each subcategory from same parent category?
- No hierarchy in wp_list_categories with child of and depth
- How to check a category checkbox using JavaScript
- Need help to structure our a complex hierarchy
- global categories – Share specific categories in wordpress multisite
- WordPress update 4.7 – the 70.000+ news posts became “Uncategorized”
- How Can Hide Define Category in Post Contents?
- How to auto update post title and slug with category name when post status is updated
- 404 error when i try to search by category or by tag
- Choosing different templates for categories
- Problem with wp_list_categories
- hierarchical taxonomy in permalinks? using same slug
- Display one post on category.php: Wrong featured image
- WordPress Numeric Pagination with Query String [duplicate]
- Changing Permalinks for Category Pages Only
- Taxonomy for custom post type not found
- Ajax call activate after submit in edit-tags.php page
- How can I get this code to only output one link?
- Sorting Woocommerce products by category and attributes
- How to get Woocomerce categories count
- show posts from some category and sort by advance custom field
- Open everything in new tab
- How to remove the category from the url only for a specific category of articles on wordpress