I found the answer here.
Add to functions.php the following function and hook:
function sgr_show_current_cat_on_single($output) {
global $post;
if( is_single() ) {
$categories = wp_get_post_categories($post->ID);
foreach( $categories as $catid ) {
$cat = get_category($catid);
// Find cat-item-ID in the string
if(preg_match('#cat-item-' . $cat->cat_ID . '#', $output)) {
$output = str_replace('cat-item-'.$cat->cat_ID, 'cat-item-'.$cat->cat_ID . ' current-cat', $output);
}
}
}
return $output;
}
add_filter('wp_list_categories', 'sgr_show_current_cat_on_single');
Related Posts:
- How can I get posts in a subcategory to display on it’s parent categories archive page?
- Custom category order with get_categories
- Custom sidebar category listing?
- Auto add taxonomy if post has category
- Show posts on a page based on a category and tag(s)
- Query posts by category AND custom field, then ORDERBY another custom field – help!
- How to add “Read More…” link in twentytwenty
- how to get the categories for a single product in a hierarchical way
- Automatically check parents (in a taxonomy) when child is selected
- Category selectable homepage
- How to change the category url jusy show /category/%category_id% in wordpress?
- How can I create a permalink with two categories, with the order based on the parent category?
- How do I list custom taxonomy terms with the links?
- Get whole linked with wp_list_pages
- Adding Multiple “Parents” in get_categories
- How to setup a membership system in WordPress?
- Make the home page template my archive/category page template without code duplication
- Get custom text if in Category
- Create Miltiple Category Base
- Is it possible to edit a wordpress category with Gutenberg?
- How to show related post with category DESC (ASC) IDs of ID current post
- Hide entry-header for a specific category
- How can I add category variable inside posts?
- Post thats in Two Categories, only want to display name for one
- woocommerce display product category on checkout page [closed]
- Prevent posts from being published if the ‘Uncategorized’-category or no category is selected
- Show last child Child category instead of first child category on page
- wordpress categories narrow down results
- Modifying posts based on category in TwentyTwentyTwo theme
- get_pages() not ordering as it should
- WordPress Multiple Category Search
- WordPress objects class reference
- Customizing gallery shortcode in 3.5
- Can You Export Theme Settings From WordPress Multisite?
- How do you add pages on a staging server, and then move them over to production
- Any Hook Called When Post Becomes Published?
- Automatically wrap post image in div
- Theme Twenty Fifteen: Customize Color Scheme Customizer
- Select category in custom query
- Is it possible to set default values for custom fields in a custom post type while my plugin is being activated?
- Format Brand value in Category view [closed]
- WordPress Template not affecting the working, keeps defaulting to the index.php template
- Custom Widget form function common elements
- Reinstall WordPress Without Losing Data
- Paginate Author’s Post List on Custom Author Page (ANOTHER THEORY)
- WP Northwind for Theme Development?
- list/consult Taxonomy only for the respective author/creator in dashbboard
- How to insert a sitemap within a subsite when using WordPress multisite
- How to check if site is created by wordpress? [duplicate]
- Enabling Additional CSS / custom-css
- Child Theme – how to add new widget on a specific place?
- Modify Gallery Output to render differently on a PAGE and a POST
- How to Call a static page in WordPress
- How to select posts from multiple categories and metavalues?
- Add google org chart to wordpress page
- I’m using add_meta_box() but want to include TinyMCE editor *and* Media Uploads for each box
- How-To add Custom field in WordPress wp-ecommerce Categories?
- The function can not create a table on MariaDB server
- Child theme .css files are not overriding their parent .css files
- One WordPress Installation for 2 Domains
- Set Title from Custom Template
- For a specific theme, how do I build a list of all the possible theme modification names?
- Post thumbnails not working in my new install of WP 3.1 with Twenty Ten theme
- Switch between WordPress websites easy for an end user
- I’d like to be able to programatically setup a site to discourage crawling by search engines
- How can I apply custom sanitization to new usernames?
- Divi theme: change overlay color from default blue to back [closed]
- How to create custom layouts and static pages in themes for clients
- failing to display a custom font [closed]
- custom query for both category and pages using global $wpdb;
- Dynamic Sidebars based on page name
- How can I create a basic PHP that can lives outside WP?
- Make a difficult page editable
- Can I style single post that are in multiple catergories?
- Overstand theme set up issue
- Simple custom attributes on posts
- Add producthunt badge to wordpress menu
- Polylang will not allow changing of language without translation
- How to assign a default/priority taxonomy to be shown in url in case two taxonomy items are selected
- Custom query pagination with php parameter as arg problem
- Perform javascript when an input in Customizer is selected/focused?
- Problems with running a 2nd installation of WordPress on my domain?
- Change the WordPress > Error title?
- How to implement custom Javascript to my site
- How do I enable the text editer in my WordPress theme? [closed]
- Style Radio Buttons inside Edit Page (Custom Fields)
- How to display all post from the same current usermeta
- Having a forum in a subfolder
- How to echo custom styles in css format?
- Define excerpt length by inserting read more tag
- Add date under slider/grid featured content
- Apply `the_content’ filter to theme customisation live preview
- Using Custom Fields in post, need to put into the_content
- Create advanced portal website with sections – taxonomy usage?
- Custom Query for Taxonomy
- Why should I keep my personal WordPress separate from my “professional” one? [closed]
- Woocommerce custom taxonomy order
- Edit image alignment in WordPress twentysixteen child theme on attachment page [closed]
- WordPress Home page modification [closed]
- Woocommerce send custom email receipt based on product attribute