Show only category name and url on WordPress’s website/theme using php code, This code can be helpful when you will create breadcrumb schema structure.
Example:
home > how-to > wordpress > add sitemap on website
how-to that is parent category’s name.
Use These code and Show Only Parent Category Name and URL
Parent Category’s Name
<?php $category = get_the_category(); $parent = get_category($category[0]->category_parent); echo sprintf($parent->name); ?>
Parent Category’s URL
<?php $category = get_the_category(); $first_category = $category[0]->category_parent; echo sprintf( get_category_link( $first_category )); ?>
Use these code without any worries, If this code not work on your current theme, So contact theme developer. Thank for visiting.