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?
- 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
- 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
- Root level category, tag, author and archive pages to work
- 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”?
- 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]
- Multiple category selection in post, shows less important category in breadcrumb
- I want to display the all the posts that are inside a certain subcategory
- Category template with pagination returns 404 on next pages
- Display custom taxonomy attached to the post on post single page
- Ive got a term (get_term_by) but now I want to filter it by a category it is in?
- Get and show all of the available categories
- how to remove the default title of Categories widget
- Recent post by custom select query
- Add custom code at start and end of all posts in a category
- How to get posts by category at /%category%/ url?
- Group search results by category
- Custom row actions on a specific category
- WordPress monthly archive category specific
- Show multiple categories in query using redux framework variable
- Add multiple orderby with pre get posts
- new WP_Query issues
- Is custom menu name and category name linked in wordpress?
- “Special” category is displayed in all categories or show parent category on sub category
- add woocommerce archive description if exist
- Can’t display posts by filtering categories using isotope.js
- Get a list of categories, separated by / to display inside the for custom metatags
- Is there a reason to put a product in both the Child and Parent Categories?
- Get_term_meta() always returns false
- How to list all categories a post is in, but exclude current post´s category on single post page
- Get only children category name
- Displaying only selected categories
- No results found for second level category
- get_the_category vs wp_get_post_categories
- How to get get_categories()’s ‘hide_empty’ argument to work with global year var in the archive template?
- Categories in media library
- WordPress Shop and restricting products and categories for some users/groups
- Pass list of categories to JS
- WP url to get rss with full text of post
- Paginating a list of all posts collected by category titles
- Customize category query in widget
- Page permalink rewrite
- Trying to WP_Query a category
- Woocommerce Force the category choice before creating new product? [duplicate]
- how do I exclude a category foreach
- CPT Custom post type Tags & Categories not showing for ‘Editor’ user in editor