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?
- How to target with css, admin elements according to user role level?
- Getting key value of WP_Term object in wordpress
- Best way of adding CSS which can be manipulated by the user via theme option panels?
- Need help on WordPress and php
- Looking to exclude blog posts from category Previous/Next buttons
- Multiple pages on one with different HTML
- WordPress Customizer not setting default value upon initial install?
- wp_enqueue_style with style.php and WordPress functions
- Minify HTML, CSS, JS with PHPWee?
- Add HTML Attributes To Anchor Tags In `wp_list_categories()` Function
- Add a Different CSS Class Into The Body Tag of Different WP Pages
- Show post in slider
- Where do posts get the sidebar from?
- How can I hide Home in my menu in a specific page?
- get post based on category chosen in drop down – The ajax method
- Slider loading issue
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- how to remove metadata from the posts of my blog?
- Proper syntax or method for keeping url in modified isotope / category links
- how do I get a specific post from a post with a subcategory in WP
- Get page that displays all children of taxonomy parent
- selected option if current category is the value
- How to add condition in wordpress loop? [closed]
- Alert Bar section within WP loop is displaying even though there are no posts
- WordPress Multiple Navigation bars
- 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
- Change CSS based on is_user_logged_in
- Change “No Comments” link to “My String” on Blog Post (Find Snippet in Code or use CSS, PHP Solution) [closed]
- Where can I find the inline-css of my theme header?
- How to get category name or ID by post?
- Post not populating for custom post type based on category selection
- Menu Custom Data Attributes
- Listing titles and custom fields of entries within subcategories
- Highlight the links without using dropdown
- random display categories – change url
- Do not duplicate posts with multiple categories in multiple loops
- How to modify mobile nav menu text in theme
- Removing sidebar on category pages
- Dividing the loop to style post differently
- How to add new CSS file to new PHP file
- wp nav menu: show submenu below li item
- go to home page when i select default in select-box
- Adding wp_list_categories to a specific div that was appended using jQuery
- Styling an “active” link outside of WordPress default menu
- I get “Cannot modify header information – headers already sent” when I change my theme
- How to edit background color of only one sidebar?
- How to sort posts by active category in WordPress?
- Counting number of posts in multiple (sub)categories using shortcode
- How to find which .mo file is responsible for displaying a particular localized string?
- Add css class to string
- Change category thumbnail size
- Removing links from Grouped products
- Display Visual Composer shortcode if a post belongs in specific categories
- WordPress custom php script to match standard page layout
- Get parent category name when only child category is applied to a product
- Help me I cannot link my font-awesome to my WordPress Theme. I have my font-awesome folder already in my project
- Multiple Tag Filtering
- Google CSE Malfunctions via Chrome/Safari on Mobile When Clicking on Either Search Icon/Menu Icon. How to Make Google CSE Default Theme Search
- Polylang and template files
- Notice: Undefined variable
- Hide author from search results meta, still display date and categories
- How to locate parent theme functions and add functions to my wordpress child theme?
- Add my footer menu to the header
- Show subcategory name selected in specific category woocoommerce
- Trying to add get_the_title hook to this line
- Custom content using in_category
- How to display post_content from database in different on template page?
- remove blank space where sidebar was
- PHP drop down menu for my get_category child of
- Short code into PHP
- Need to adjust condition to say if I’m pulling categories from a post, to pull only the first one
- Widget edit and add in any page
- Rearrange get_categories array compared to another array
- Styling admin page rows in order of importance (checkboxes)
- How to save the output of php variables used in inline css code to the main style.css?
- Search in particular category in wordpress
- Query seems to be duplicated
- Top menu disapears in Category Pages when filtering using ACF
- featured post as div background
- Combining fancybox with multiple thumbnail plugin
- Trying to customize wordpress drop down categories
- Error trying import one category on page
- Show Nav Link To Users Signed In
- Remove the_content From Loop
- Category List in Theme Options Page
- PHP Puzzle: Unique Styles with PHP loop
- How to use plugins_url() inside PHP stylesheet file [duplicate]
- Display post of specific category on page
- Displaying categories
- Integrating CSS Into a WP Function Call [closed]
- WP_Query not returning results
- How do I link the side images?
- How to create a container in php then customise it in CSS
- inner-wrap div pushing custom table far down on page
- Styling best practices for single pages/templates