Hello guys, I’m trying to change the way my post is showing the category name. Currently, is displaying all the category names where the post is, but I want to show the main category only.
I know that I need to change this part:
$cat_name = maddos_get_post_categories( get_the_ID() );
But my php knowledge is a little poor…
Can someone help me, please? 🙂
Thank you in advance
Full code:
<?php
$icon = function_exists( ‘get_field’ ) ? get_field( ‘site_icon’, get_the_ID() ) : null ;
$icon = apply_filters( ‘maddos_get_icon’, $icon );
$site_icon = $icon && filter_var( $icon, FILTER_VALIDATE_URL ) ? “<span class=’maddos-title-icon’><img width=’16’ height=’16’ alt='{$title}’ title='{$title}’ src='{$icon}’ /></span>” : “<span class=’maddos-title-icon’>{$icon}</span>”;
$header_tag = is_single() ? ‘h2’ : ‘h3’;
$title = $header_tag === ‘h2’ ? get_the_title() : sprintf( ‘<a href=”%s”>%s</a>’, get_permalink(), get_the_title() );
$cat_name = maddos_get_post_categories( get_the_ID() );
?>
<?php printf( ‘<%s class=”maddos-post-header”>%s %s<span class=”maddos-post-header-category”> – %s <span class=”glyphicon glyphicon-folder-open” aria-hidden=”true”></span></span></%s>’,
$header_tag,
$site_icon,
$title, wp_kses_post( $cat_name ),
$header_tag);
?>
