Try this:
$post = get_post(); // If $post is already available, skip.
$terms = get_the_terms( $post->ID, 'category' );
foreach ( $terms as $term ) :
if ( $term->parent === 0 ) :
echo '<a href="' . esc_url( get_term_link( $term->term_id, 'category' ) ) .
'" title="' . esc_html( $term->name ) . '" ' . '>' . esc_html( $term->name ) .
'</a> ';
endif;
endforeach;
Related Posts:
- How to check if I’m on the last page of posts?
- Where/how are categories stored?
- Get top parent category
- wp_update_nav_menu_item() to insert categories
- How to exclude uncategorized from permalink structure /%category%/%postname%/
- Redirecting specific category posts to subdomain
- How can I prevent users from creating new categories?
- Get child categories when clicking on parent category
- How can I create a loop to build slides based on multiple categories using Coda Slider
- Saving two categories from two dropdowns in front end posting form
- Block multiple categories from Blog
- Best and Cleanest way to remove /category/ from category permalinks? [duplicate]
- Categories list loop – add separator every year
- What type of page should i use? static page or category page? and what’s the difference? [closed]
- Filtering by Category doesnt paginate correctly on the backend
- Direct link to category?
- Categories vs. Page Site Organization
- Sorting posts by season
- How do I add a function on a specific post category?
- Open subcategories in submenu on click in primary menu
- How to add Categories to the top menu of the website?
- force category base – archive pages work WITH & WITHOUT category base slug in url?
- Retrieve Image from Media Library by it’s category
- Getting URL of archive (category) page
- Strip a word from wp_list_categories
- List all the categories with or without post
- Site search needs to find posts for category topic AND Tag or keyword thats not in the post
- Get category url in loop
- Previous/next post links displaying wrong category than is desired
- SQL to migrate post types to taxonomy
- Order by category titles
- How to conditionally hide author name on Single.php if category is “news”, otherwise if category is something else display author name?
- How to let users choose posts order in categories?
- WordPress category
- And/Or Category Query
- Automatically redirect a page to a category that share the same slug
- How to put an array in is_category
- Show subcategories on a parent category page
- How do I add Category Body Classes to Admin?
- Is there a reason I cannot get the current category in a loop?
- How to get parent category ID in single page template
- “Item not updated” when try to change category properties
- How can I tell what category I’m in– in the header?
- new WP_Query all post in a category inside the loop
- How to display sticky or latest published post on the current category page it belongs to?
- How do I add a separator to my list of terms with get_category
- Category tags with comma’s
- Trying to create a Categorised Index (archive?) to use as my Home Page
- Filter posts by categories ajax is showing nothing
- How to display child categories of all parent category within a singe loop?
- How can I add a class to displays a category?
- How to show only the name of one category above each posts in frontpage?
- WP_Query – using category__and when one of the categories is 0
- Multiple categories for one menu item?
- Hide categories from frontend, but not admin / post editor
- Exclude categories from homepage not longer working
- Post to inherit custom category background image from parent
- Related posts widget – category
- Editing Loop So It Targets Specific Tags?
- Last x Posted Categories?
- Check boxes for showing categories
- Header Link function not working. Problem with bloginfo()
- WordPress category filters as subcategories
- Sort posts alphabetically by category/custom taxonomy, insert divider between different types
- Need help with major category and permalink re-organization
- Include home page template in specific category template
- Is there a “sensible” limit to WordPress Categories?
- Display Category Name and Date Posted on Blog Post
- Modifying category order
- How to remove “Categories:” part after the post title? [closed]
- Please tell how to stop the category from showing up on posts
- how to get only grandchild category from a child category
- Editing categories crashes WordPress site
- Remove “category” from permalink with add_rewrite_rule
- Next and previous links category infinite loop
- How to hook into creating a category?
- Conditional Site Logo(Category Based)
- show only terms from parent category
- show posts in archive page based on selected catagory
- Tag Menu items based on their categories
- Accessible Subcategory URL’s pages without using .php hack
- How to display total views of all posts of one category?
- Get the categorie name of Event Organiser plugin [closed]
- in_category(‘category-sluga’) returns true for Archive page of Category ‘category-slugb’
- wp_list_category only showing to logged in uers
- Grouping parent categories into sections
- How to show “category” name?
- Display the category name of a post that is in two different categories
- Querying Multiple Categories With Different Offsets
- filter single_cat_title avoiding the breadcrumbs
- htaccess redirect for all categories converted to tags now showing 404
- Category page with gallery for each post
- (WordPress) How to get custom taxonomy parent name?
- add new input field like category?
- WordPress excerpt for specific posts in category
- How do I get a single page navigation depending on the previous page?
- Search functionality with multiple categories
- Make a menu visible for a single category and it’s content
- WordPress Loop Prob
- How to define category ID in an array?