Get primary category
-
Hi, I’m trying to figure out if “Primary category term” is a Rank Math option. And I think so.
How do I insert primary category term in a php file where the various categories of a post are called. Then replace all categories, only with the primary category.
This is the post block code (if it can be useful):
case 'cats-alt': if ( 'post' == get_post_type() ) { $categories = get_the_category(); $categories_list = ''; if($categories){ foreach($categories as $cat) { $categories_list .= wp_sprintf( '<a href="%s" title="%s" class="cat-tag bg-by-cat %s"><span>' . $cat->cat_name . '</span></a>', esc_url( get_category_link( $cat->term_id ) ), esc_attr( wp_sprintf( _x( "View all posts in %s", 'entry-meta: post cat(s) title attribute', 'wp-post-blocks' ), $cat->name ) ), $cat->slug, esc_html( $cat->cat_name ) ); } echo wp_sprintf( '<span class="cat-links meta-info">%s</span>', $categories_list ); } } break;
Thanks for the support
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Get primary category’ is closed to new replies.