Display ONLY Primary Category in Blog Meta

#63202
  • Resolved Sophie Pearce
    Rank Math free

    Hi there,

    As I tag my posts in quite a lot of categories, I would like to display ONLY the primary category in my blog meta. So, on a single post, there is only the Primary category shown to the user.

    I have found lots of CSS codes for the Yoast plugin, but not for RankMath as I suspect they will have completely different terms. (I have posted the code in the ‘sensitive’ area).

    I’ve searched on the forums and there doesn’t seem to be this query for this yet.

    I would appreciate some help, please 🙂

    Thank you
    Sophie

Viewing 1 replies (of 1 total)
  • Alberto
    Rank Math business

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    You can easily adapt the code snippet you shared with us to work with Rank Math since you can use the following code to get the primary category of any post, product… In the following example we get the primary category of a product:

    $primary_cat_id = get_post_meta( $product->id, 'rank_math_primary_category', true );
    if ( $primary_cat_id ) {
        $product_cat = get_term( $primary_cat_id, 'product_cat' );
        echo $product_cat->name;
    }

    Looking forward to helping you. Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Display ONLY Primary Category in Blog Meta’ is closed to new replies.