You can do this using WordPress’s handy body_class()
function. Depending on whether and how it is used in your theme, it may already be giving you what you need. Here’s how to find out:
Check the source of your page to see if the <body>
tag in your category archive pages has any classes containing your category slug: category-apple
, category-area
, category-usa
, etc. These will typically be included by default.
-
If they are there, you can use these as selectors in your CSS:
body.category-apple { /* code here */ }
, etc. -
If not, add the
body_class()
function to the<body>
tag in your theme, probably located in header.php. It works like this:<body <?php body_class(); ?>>
Optionally, you can add any extra class you want as a parameter.
Here’s the entry in the WordPress Codex: http://codex.wordpress.org/Function_Reference/body_class
Related Posts:
- Different post styles depending on category
- admin panel – How to remove “delete” button from category editing page
- How to add style in functions.php depending on conditions?
- get current product name in functions.php
- How to stop featured image thumbnail [set as background image] on blog index page just repeating same image across all posts
- get post based on category chosen in drop down – The ajax method
- How to use transient in this code for related post?
- Slider loading issue
- Creating a related post section based on similar categories
- Plugin CSS not enqueing
- Swapping wp_dropdown_categories function with wp_category_checklist
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- Parent theme CSS overriding child CSS rules
- how to remove metadata from the posts of my blog?
- How to style options page in dashboard?
- Theme Options Page – User Updates Logo
- Proper syntax or method for keeping url in modified isotope / category links
- How to use my style.css file outside of wordpress subdomain?
- Dynamic Stylesheet loads but doesn’t finish
- How to add date to navigation bar
- Filter Select results based on selection
- Selectbox in admin panel function linking to CSS
- Can I install/embed WordPress on a ‘single page’?
- Using if/else statements with output from theme options
- Is there CSS to expand the gallery limit on Index Pages?
- What is an equivalent of single_cat_title for getting the slug of the category?
- Issue adding sub category programmatically
- How to exclude category ID from Looper in WordPress
- Add a specific part of current category page url to shortcode
- how do I get a specific post from a post with a subcategory in WP
- How to design a table based on css values set from admin/dashboard
- WP grandchild categories in nested ul li
- Grab posts by multiple categories
- Pass Category Name, Description and Photo into variables to pass to jQuery
- How to show single category archive
- Move category description below post list in blog
- How to pick the default selected value in wordpress dropdown?
- Applying A Category to Existing Posts Where Page Title Matches Regex
- Get page that displays all children of taxonomy parent
- selected option if current category is the value
- Incorrect MIME type for assets with Valet
- How to display pictures from database?
- How to add condition in wordpress loop? [closed]
- get_template_part based upon post’s category
- Customize position of social icons in upme plugin [closed]
- how to save selected option in variable for rest api category filter
- Setting default category base on theme activation
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Best way to schedule daily change in CSS parameter
- Css loads very slow [closed]
- Hide subcategories (widget)
- Gravity form built in Captcha
- Alert Bar section within WP loop is displaying even though there are no posts
- Let Users Choose Post Categories
- How does wp_enqueue_scripts work?
- How create a Shortcode with hover and complex options
- Display category name only once inside loop
- WordPress Multiple Navigation bars
- How to show only subcategories in parent category not parent category?
- two columns of posts on homepage, one of them “favorites”
- Auto 301 to full post permalink? (using : /archive/%post_id% to %post_name% )
- Whats the proper way to use a php stylesheet in a wordpress theme? [duplicate]
- custom css for admin only
- responsive.css in the WordPress should be prioritized
- How do I add a custom css to all posts without affecting homepage css? [closed]
- how to show only specific category for a template
- Redirect to another page using contact form 7? [closed]
- Which is the correct way to conditionally enqueue a CSS file?
- Custom Background by Page IDs
- proper way to add css using functions.php?
- WordPress style.css not updating, only after theme reload
- Adding logo to WordPress header
- Thumbnails appear to be zoomed
- Use PHP in stylesheet to specify a background image based on Category ID
- Dilemma of Populating all the categories in a drop down list
- Automatically set all tags to have a height of 0 if there is no content inside the tag [closed]
- height should be set to auto to avoid pixelation in the post thumbnail function
- Odd / Even posts add class minus first post
- Display most popular posts of category
- Change CSS based on is_user_logged_in
- Creating sub-categories via php
- Define specific category name in PHP
- RTL Stylesheet Confusion with WordPress
- Correct way to enqueue page specific CSS file
- Edit the_category (); for a hierarchical display
- Wrapping a Sidebar within
- JSON REST API WordPress only showing first 10 categories
- Category title output before opening title tag
- get taxonomy thumbnail and use it as a variable in code
- Add Codepen animation as Preloader to WordPress
- Include Parent Term in wp_list_categories
- WordPress wp_add_inline_style unable to give hex colors?
- Reduce size of responsive title
- How to make container class in PHP
- How to array only one key from another array
- How to create table in wordpress without plugin? [closed]
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- WordPress archive page showing 404 Error [duplicate]
- Get all categories post is not in
- Get latest post from all categories except one