Category archive pages can be styled using the body class as per your example – WordPress does this out of the box. But for single pages, you need to add this to functions.php
:
function add_category_name($classes="") {
if(is_single()) {
$category = get_the_category();
$classes[] = 'category-'.$category[0]->slug;
}
return $classes;
}
add_filter('body_class','add_category_name');
This will add the body class to the single post, and you can style it with CSS.
In order to change the header text, you’ll need to use a conditional statement in your archive page template.
if (in_category('this')) {
echo 'this';
} elseif (in_category('that')) {
echo 'that';
} else { }
Related Posts:
- Hide post meta data on a specific category
- Different CSS class by category
- How to prevent page re-sizing for mobile browsers [closed]
- How to create an automatic MultiColoumn MegaMenu with Categories WordPress
- Gutenberg editor add a custom category as wrapper for custom blocks
- How can I hide a category from Contributors in the edit/add new post screen?
- WordPress Multiple Category Search
- Decreasing the Memory Consumption of a WordPress Site?
- Multiple Domain Names – One WP Install (non-Multisite) – Default Each Domain name to Category Archive
- How can I select a primary category?
- how to use a different domain/subdomain for authors/catagories on single site?
- Deleting default category in wordpress
- Delete a specific category when deleting a user
- How to list child categories in custom category template?
- Trash bin for categories
- View category in the preview of Theme Customizer
- Create a full width responsive header image per page
- One WordPress Install, Two Categories. Each Category Gets a Domain
- Block multiple categories from Blog
- Create single.php for specific category by category id
- Show posts of one category only with Custom Taxonomy on single.php
- Save metabox checkboxes values to custom content type
- Select category in custom query
- Remove “Parent” Selection When Adding/Editing Categories?
- Order Taxonomy Term by date created
- Apply custom category template to subcategories
- Add custom taxonomy under the category title
- How to show in search results posts with a particular tag in a particular category?
- Multiple menu items highlighted
- Use a wordpress page to display a certain category
- Different excerpt styles per category, but chronological
- How to view WordPress’ default category IDs?
- Multiple Category Search
- How do I add a function on a specific post category?
- How to customize category template?
- Category-slug.php not being used
- How would I go about adding custom header images per category?
- Highlight wp_nav_menu when category is selected
- Display posts separated by Category in Author’s page
- Hide woocommerce category name from specific pages
- Hide woocommerce category name from specific pages
- How to categorize posts under Category 1 and Category 2 which are separate lists of categories, and display them as separate lists in widgets
- Filtering *out* a taxonomy from the admin post list
- How to rewrite the post URL according to the category?
- How to build a simple nav system of custom post type categories and its posts?
- Style category link depending on category ID
- Inside a loop, how to change CSS class based on category name?
- Redirect to another page using contact form 7? [closed]
- Display thumbnails for certain category posts
- Why do I have stray bullet from
- Is it possible to remove from default category widget?
- How to customize my category pages
- How to add custom color fields to the category edit page?
- Multiple selection for wordpress widget
- Wrong category nice name is displayed on archive page
- Simple way to style posts of a single category differently in the loop and in single
- How can i change what one category displays?
- Remove any product that is featured from regular display loop [WooCommerce]
- Two Sections on Woocommerce Catergory Page [closed]
- Remove Archive | from Categories
- How to let the user create a selection of categories via the backend
- Restrict CSS on one page
- How to hide widget from certain category
- custom query for both category and pages using global $wpdb;
- I would like to feature a tip on the homepage
- Show Secondary Sidebar on Category pages (archive)
- How to add icon over specific thumb
- Problem with Custom Post Type Categories
- List post only under the category, exclude child category content
- SQL query to get posts from multiple categories but not in a category
- wp_delete_term or wp_delete_category?
- Select posts that match multiple category names, must match all categories listed
- Custom Portfolio Page
- Last x Posted Categories?
- show only sub categories if available?
- How to get sub-categories to display same look as there parents
- How to add meta description, keywords, custom title to a category template
- separate posts to have (kind of) 2 blogs?
- Inline If statement to echo CSS [closed]
- How to “remove” WordPress categories UL and make the list loop in a horizontal line?
- problem with filter of custom portfolio categories
- Deleted categories still listed until additional page refresh
- How can I make a category function as a page?
- Category custom template is not showing correct posts
- Search Replace Database ONLY for posts of certain category?
- Filter custom taxonomy posts via AJAX
- Inserting categories as a hierarchical terms from frontend form
- Show posts from all categories
- How to add a post with new Taxonomy without assigning to default category?
- Getting page/category content to show up in my custom page template
- If it is a top level category show children otherwise show sibling categories
- Own Custom Tags/Category page ( posts)
- How to create default categories in new installs?
- Custom CSS to resize elements in multiple categories
- List all authors by matching custom meta data on a category page
- why is the delete option missing from just one category?
- Broken category styling
- Woocommerce custom taxonomy order
- How to hide my categories pages’ names, and how as well to reduce the space beween my sidebar’s widgets?
- Modifying posts based on category in TwentyTwentyTwo theme