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
- How to display related posts by subcategory and not parent category
- How to display following posts titles in separate div’s on a separate webpage
- 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
- Prepending %category% onto default posts fails
- List all categories with featured image from post?
- How to list recent posts in a wp nav menu?
- Dynamic dependent Dropdown lists for categories, sub-categories and posts
- WordPress is replacing double minus signs in Post Title, how to disable it?
- How to display two blog categories as separate sections on one page?
- why does wordpress ignore the post args?
- Loop doesn’t show title of second post and posts thereafter
- get posts from Custom Post Type & Category
- How to create a “latest news” page showing a list of posts from blog category
- Edit the post title from the frontend
- How to enable custom Shortcodes in Post Category Description? [duplicate]
- Sort by last word in title
- Image behind the post’s title
- How to call posts under a specific category on static front page?
- Give posts a particular template based on the assigned category
- Post-Archive like a page in a specific subdirectory
- How do I display the post_title with get_permalink?
- If post exists, make it a comment in existing post with same name?
- How to display only one category in a custom post type?
- Get only X number of categories
- inserting a category into post
- Getting posts from some categories plus some individual posts
- Change layout of post depending on category
- latest post showing up twice on posts page
- wp_list_categories() Exclude All Categories Except One
- Different post views for different category views
- Possible?! A contextually titled back link
- Allow / show post comments in category pages
- how to show current date on post title which should be auto update in every day
- Adding Text after Post Title based on Category using IF Condition – But not for menu items
- Display default matabox of posts(add category) wordpress
- How display related post only in Default category on single
- How to merge the content of posts that have the same title?
- How to get tags when using publish_post
- How to add class to specific navbar item when post parent category is in specific category
- How do you change the permalink for posts for a single category?
- Posts are not displaying on their category and tag page
- Does having category name in permalinks affect SEO when having a post in multiple categories?
- how to create a category with wp_insert_post and post_category
- Exclude posts in a category on one page but show those posts on a different page
- How to add a block to a category page?
- Add id attribute to h1 element of wordpress post
- Excluding category from post navigation in WordPress?
- Odd hyphen added at end of blog post
- Show custom post category for single post
- Get a list of categories that are related to posts
- Dynamically load posts based on category
- Querying posts from current category, using a variable as array argument
- Precedence of page permalinks over woocommerce product category links?
- Need help writing loop to display posts by categories in separate divs
- Add category selection to function request
- Query post category & remove any post id
- Admin Post List Only Show One Category
- Multiple Post Repeat for Related Post Loop by Category
- Show Post number of specific Category
- how to show posts on different pages if number of post per page is one
- Get post title of faulty link on 404 error page
- Is possible to create a custom link that creates a post that’s already categorized?
- Is there a way to separate wordpress titles from their posts?
- Viewing category won’t show up Custom post type posts
- How remove “recent comments” title without modifying code? [closed]
- Show Title/Date/Excerpt of first post & only Title for rest in Query [duplicate]
- Listing category and its posts one by one
- Print out one of 2 post category [closed]
- How to get if category has posts?
- Show some texts in posts belonging to Specific category
- Sort Posts Alphabetically Based on Specific Category (Divi)
- I have a website issue I am trying to resolve
- How to sort posts alphabetically based on a specific parent category