How to get parent category name in WordPress

This is the common requirement of developers when developing for WordPress is to display custom category name, category URL link, custom category id. if you are creating custom page template where you want show list of parent category.
Here am writing code to display parent category name of WordPress . First it gets the category name of WordPress post, and from it gets the Category ID of its parent then it gets the parent name with get_cat_name() function.

<ul class="cat_list">
    <?php
    $args = array('orderby' => 'name', 'hierarchical' => 0, 'parent' => 0, 'style' => 'none', 'taxonomy' => 'category', 'hide_empty' => 0, 'depth' => 1, 'title_li' => '');
    
    foreach(get_categories($args) as $category)
    {
    echo ' <li><a href="' . get_category_link($category->cat_ID) . '" title="' . $category->name . '">' . $category->name . '</a> </li>';
    }
    ?>              
</ul>

Leave a Reply

Related Posts: You may like

How to track contact form 7 form in salesforce without plugin

Contact Form 7 Redirect to Thank You Page

How to Validation Business Email in Contact Form 7 WordPress

How to Create and get WordPress Custom Field

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Download Instagram Videos & Photos.

Download Now

CURRENCY CONVERTER

Real Time Currency Converter

Convert Now

ROBOST.TXT GEN.

Robots.txt File Creater

Create Now

HTML MINIFIER

Compress yout HTML Code

Minify Now

CSS MINIFIER

Compress yout CSS Code

Minify Now

JAVASCRIPT MINIFIER

Compress yout JavaScript Code

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.