If you have a single level of subcategories under your main categories, you can just do this:
$category = get_category( $cat );
if( $category->category_parent ):
$parent = get_cat_name( $category->category_parent );
echo '<h1>' . $parent . '</h1>';
else:
echo '<h1>' . $category->cat_name . '</h1>';
endif;
Related Posts:
- How to create an automatic MultiColoumn MegaMenu with Categories WordPress
- Create a full width responsive header image per page
- Remove “Category Archives: title” at the top of a category page [duplicate]
- Hide post meta data on a specific category
- Different excerpt styles per category, but chronological
- Highlight wp_nav_menu when category is selected
- Category location styling
- Hide woocommerce category name from specific pages
- Hide woocommerce category name from specific pages
- Style category link depending on category ID
- Inside a loop, how to change CSS class based on category name?
- Why do I have stray bullet from
- How to add custom color fields to the category edit page?
- Different CSS class by category
- Simple way to style posts of a single category differently in the loop and in single
- Remove Archive | from Categories
- Custom css per category and per single post belong in each category
- Restrict CSS on one page
- Show Secondary Sidebar on Category pages (archive)
- category description not showing in my woocommerce
- Inline If statement to echo CSS [closed]
- How to “remove” WordPress categories UL and make the list loop in a horizontal line?
- Custom CSS to resize elements in multiple categories
- Custom Woocommerce Category view
- Broken category styling
- How can i hide the authors box from a specific set of categories and post types?
- How to prevent page re-sizing for mobile browsers [closed]
- How to hide my categories pages’ names, and how as well to reduce the space beween my sidebar’s widgets?
- How can I get the categories and subcategories separately?
- Elementor : display only one category in loop grid
- WordPress Multisite – global categories
- Get posts from sites in Multisite?
- Retrieve Product category ‘NAME’ by product category ID – WooCommerce?
- Can’t custom taxonomies have same terms (slugs) as categories?
- Using wp_category_checklist in a widget
- Filter front page posts by category
- How to get the url to tag & category base set by the user?
- Exclude one category from get_the_term_list
- WordPress remove separator from last item in wp_list_categories
- Filter categories using tags
- Need help adding custom field to category
- How to Include the Parent and Child Category in the Permalink if the Post is Added to Both
- How to display a list of categories
- Number of posts in page – set per category and exclude sidebar
- Create single.php for specific category by category id
- is_category in pre_get_posts results in php notices
- Use get_term_children to get the sub category of a parent category for the current post
- How to make all posts in a category “unsticky”?
- How do I get the total number of categories in a list of search results?
- Get a variable from object in array [closed]
- How to stop wordpress from showing the selected category on top of others in the category selection?
- advanced custom field Show field in special categry page [closed]
- Exclude Child Categories Using wp_list_categories
- How do I get a list of all categories that a given user has written blog posts for?
- Linking products to categories
- How to remove “Category : …”
- “Categories” on my front page [closed]
- Add “page-a” slug to category link if user visit category link from “page-a”
- create a page which displays a list of categories title+ short description?
- Query Posts Exclude Entire Category
- select parent category first then child
- How to exclude children categories of parent category
- Menus don’t work after 4.4 [closed]
- Category template to show different categories based on parent
- Customize category page for different custom taxonomies
- Conditional IF current cat is the smallest/last/end child cat THEN
- How to create a custom meta box field in category? [duplicate]
- How to show 1-5 of X Total Results
- SQL query to return categories and category parents
- How to Remove a Title from All Category and Tags Page?
- WordPress Show Parent Category Description for Sub-categories
- How to not display subcategories in Recent Posts widget area?
- Getting the Most Recent Posts from Multiple Categories
- How to store category and tags separatly on wordpress?
- Get post content intro text on category.php?
- How to add tags under categories
- How to add commentary types or category for a post
- How to change current category to another in wordpress
- show thumbnail for subcategory wordpress
- Pagination for custom categories template
- How to modify custom category field from front end?
- Excluding particular category from displaying in specified areas
- Category name as page title
- Bulk Change WordPress category Slug
- How to use categories, sub-categories and customize navigation view
- Hide empty category on woocommerce
- Adding a category view to a page
- make categories editor unchangeble for my post_type
- same permalink for parent category and child category
- If it is a top level category show children otherwise show sibling categories
- Hiding any option or menu from menubar
- Sidebar Categories change arrow when subcategories are shown on click
- How To Disable Category Hierarchy In Categories Widget?
- Show custom menu in category and its posts
- What approach should I take for this URL structure?
- Chained drop-down menu for custom taxonomy using chained.js
- How to display the posts belonging to a paticular category
- WordPress 3.5 how to determine if user is on category listing or category edit screen?
- Javascript code for Category
- How Do I Add HTML Support to the Additional Category Description Field?