If the changes you need are strictly CSS, you can add the category names as classes to the body_class
via the body_class
filter.
add_filter('body_class','wpa76627_class_names');
function wpa76627_class_names( $classes ) {
if( is_singular( 'product' ) ):
global $post;
foreach( get_the_terms( $post->ID, 'product_cat' ) as $cat )
// maybe you want to make this more unique, like:
// $classes[] = 'product-category-' . $cat->slug;
$classes[] = $cat->slug;
endif;
return $classes;
}
This code checks if we are viewing a single product page, then loops over all product_cats, adding the slugs as classes to the body tag. This could also be adapted for any post type or taxonomy.
Related Posts:
- Different template of products for specific category. WooCommerce
- Woocommerce single product image blurred and small. Actual image is big
- Twenty Ten Theme: Replace the Logo by a picture without moving the code
- Changing appearance of WooCommerce product layout [closed]
- Stylesheet not being loaded? [closed]
- problem with my my theme “search.php”
- How to deactivate the text, that appears, when you hovering over topbar tabs? [closed]
- WordPress without a theme – help!
- How do I combine a theme with a plugin
- How can I list all installed plugins/themes/versions from CLI/API?
- Unwanted edit link on front page
- My single.php page does not show the related data to the post which is clicked
- What hook is the currently active theme’s functions.php file loaded on? [duplicate]
- Need help with making a website where user can add products
- How can I manually activate my previous theme without browser access to dashboard?
- WordPress root directory change + Theme directory change
- How to switch theme if the current user is admin?
- Where are theme codes located for WordPress?
- Advantages of wordpress theme vs wordpress as a backend only [closed]
- Determing number the query ran by core wordpress
- How to get theme screenshot
- Finding and disabling ‘rogue’ stylesheet from header: Source Sans Pro
- Cannot apply custom css to IE in the theme
- Preserve theme settings when migrating from local to live
- Unable to access wordpress login.php [closed]
- Is that a malicious code?
- Make multiple pages and set template/content on theme activation?
- after_setup_theme is called three times
- How to restore file or theme?
- Theme doesn’t support shortcodes
- Losing all my text and entries on ColorWay Theme
- A /proc folder in wp-content?
- how do i in ignore/disable/delete a javascript call from parent in child theme?
- Overwrite category head title
- Permissions for installing themes and files in general?
- My new WordPress theme based on the TwentyEleven theme doesn’t display the front page OR the blog page
- Functions containing parameter ‘yourtheme’
- How to dynamically change theme’s slogan from admin?
- Frameworks for Premium Theming [duplicate]
- Using WordPress Multisite to manage multiple projects?
- How can I show full text, not summary for the homepage and in categories?
- Problem Installing a Premium Theme– File Permission Issue on a Mac, Local Machine? [closed]
- How to add logo in Thematic
- What’s a good way to unenqueue all scripts for a single template page?
- It’s okay if I do not write add_action()
- How to create a new copy of a theme currently being used?
- Remove problem PHP code entered into footer via Theme
- Creating a job board using WordPress (for free)? [closed]
- Basic gallery plugin suggestion [closed]
- How to transform a custom made static HTML website to a WordPress website [closed]
- Is there a way to get plugins and themes not built for multisite to work on a network subsite?
- Theme, WordPress Version, MySQL Version, PHP Version Update affected files and folders
- The Cost of Installing Custom Themes
- Can “Classic Editor” plugin help to replicate the old website / theme development experience from c. 2011?
- What is the “pub” theme? [closed]
- Can I change the WordPress default color?
- How to check if my wordpress websiste is nulled or not?
- Can I create a child theme from a premium theme without losing my posts and page etc that I already have?
- Need to edit themes HTML code
- Enqueue custom css file on specific page
- Creating custom meta box throws PHP warning error in WordPress
- What is the point of needing add_theme_support( ‘html5’) in WordPress 5.x
- How to install themes with the demo content?
- Plugin and themes are adding the same stylesheets
- i would like to have 3 default columns editable in guttenberg
- How to put single-***.php in a specific folder?
- Change copyright text on the footer section [closed]
- Jetpack CSS .screen-reader-text breaks mobile menu [closed]
- Error when using ‘continue reading’
- How to update theme to specific version
- Why does my file_exist check fail?
- Remove specific plugins and themes from the Dashboard->Updates page [duplicate]
- Create a single website with 3 theme options in wordpress
- WordPress front page empty, however, there is content on website
- Child theme’s stylesheet cannot load [closed]
- How do I remove ‘Active Theme’ section from Customizer?
- using do_shortcode
- Twenty Seventeen search error
- Protect shortcodes, custom JS, and CSS from theme updates
- Create custom pages with a plugin
- Wp theme not working well as forgot to create child theme [closed]
- Theming global variables – initializing in index.php but using in header.pho
- Cant remove white space on my wordpress [closed]
- Is it good practice moving the main stylesheets after the plugin styles?
- Icons not showing [closed]
- How to write “alt” tag in image for wordpress code?
- Variant of the same theme for each page
- Does heavy theme and plugins affect server’s response time? [closed]
- wordpress theme install failing
- can’t see aditional themes in control panel
- WordPress suddenly creating theme errors
- How to protect WordPress from security scanner [closed]
- Configure new installed WordPress in live server
- How to display footer menus in wordpress
- How to load different homepage on Mobile.?
- How do I understand which page of my theme is being loaded?
- What Generated Classes and IDs That Is Always Used On All Themes?
- Define theme information other than through style.css
- Change avatar on themed profile page
- How to get menu location in wp_update_nav_menu hook