I assume that any post belongs to only one category.
Create respective CSS classes, e.g. ‘news-header’ and ‘mindset-header’, and use following code inside the loop:
<?php
// get post categories
$categories = get_the_category();
// get single category
$category = $categories[0];
// echo header with category class
echo '<h2 class="' . $category . '-header">' . get_the_title() . '</h2>';
Related Posts:
- Add Category name to Post Title (h1)
- I want to show category in the post title , how can I do
- How do I include the category next to the title of a post?
- Change Post Title For Specific Category
- How to select a category automatically based on a word in WordPress post title?
- Create/Set Category as Title of Post
- Post Category link is same with Page link
- How to change the case of all post titles to “Title Case”
- Including categories in search results
- Count how many posts in category
- Custom Single Post By Category
- Set Post Title to Read-only and Disable Permalink Slug Editor in Gutenberg
- Convert custom fields to post categories
- Query posts from current year
- Show One Category on Post
- Do I use custom post type or something else?
- What Defines What Category A Post Picks (if in multiple)
- Limit function to specific post category
- Show all post titles
- Posts are not showing up on particular category
- Count to how many categories a post belongs to
- How to display related posts by subcategory and not parent category
- Category Template: Need to display different content on first page of archives
- Blog Posts not showing title
- How to Orderby Comments by post title?
- Display post category in foreach loop with category link
- Extracting post categories
- Using wp_list_categories like the the_category (showing just current categories of a post)
- How to limit posts by category
- Get user categories with most posts in it
- Need help with category listing!
- Prepending %category% onto default posts fails
- How do I change the core post search algorithm? Where is it found/constructed?
- Excluding posts not working
- post category in wp_insert_post
- Add title for previous and next posts to Yoko Theme
- Limit the number of posts a category can have – newest post goes in, oldest one drops out, possible? plugin?
- Remove current category from post but display all others
- How to get links to the last N posts in a specific category?
- Display posts of specific category term
- Widget that shows categories with posts numbers
- How do I show posts from another wordpress installation?
- How to show a custom taxonomy in the theme?
- How to import nested categories from XML file?
- How to get post with associated categories and tags names instead of ids with rest api?
- Replace image name on upload to the new post name on front-end form
- Migrate posts from category and sub-category via SQL
- Posts Missing in Dashboard after update
- Display post number by category
- How to get post with slug and exclude categories
- Auto update post title and slug when post status is changed
- Retrieving posts by their date and category
- Are post, page and category IDs unique to each other?
- Static pages not working
- WordPress displays post on subcategory only
- Post titles and thumbnails as links to custom post types?
- How to list post as buch of category, and all of them
- Categories Listing and Highlighting current category item
- Changing The Default Header POST Title and Description text by category in wordpress
- Display hierarchical categories/sub-categories for a single post only
- Is there a way to categorize a list posts all at once?
- Author post count in category
- On the online version of my blog posts disappear
- Why do I have categories with duplicate slugs?
- Automatic Table of contents with categories and posts
- Is it possible to remove actual post pages in wordpress but keep them in categories
- Need help with hiding an image within a post in a category
- WordPress not showing recent posts
- How to get post count including nested categories
- How to filter out post from a category not its subcategory in wordpress dashboard
- How can I display a specific number of post in a category via a url
- how to chang preview of list of articles of one category?
- Post of a specific category – not to be seen in paging previous/next post
- How to show main category related to that post
- Display selected category on post page
- Sort post by category using HTML Select tag
- Make assigning post to a specific category equivalent to assigning it to all categories
- How to use in_category?
- About number of posts in selected category
- Add default content to post (for specific category)
- List posts that are in the same category as the current post title
- display only the title of the post into a certain category
- Multiple blog “feeds” in a single blog each with distinctly styled post pages
- How to get pagination working with “Pending” Posts
- How do I show the post title if an advanced custom field hasn’t been used?
- Deleting first four characters from all Post Titles
- clicking on page title
- Post’s arent displaying
- Show with echo if a post has two or more categories
- How can I get on the same row two post of different categories?
- Title displaying multiple times
- Custom Post-Rename Function Does Not Function in WordPress 6.x
- How to change Post title background size?
- Filters do not work when there are multiple (one works)
- I want the Title of page/post to show up topmost when reading the post/page
- Show category name in category.php when posts assigned to multiple categories
- Error counting posts of category
- Comment count next to post title?
- Display posts from a specific category on frontpage.php template?
- Cant display custom post type posts from a specific category WordPress