[Support request] Display Only Primary Category in Posts

Home Forums Support [Support request] Display Only Primary Category in Posts

Home Forums Support Display Only Primary Category in Posts

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #770840
    Vish

    Hello

    I have some posts which are categorised under multiple categories. But, I would like to display only the primary category in the front end.

    How can we achieve this?

    Thanks.

    #771265
    Leo
    Staff
    Customer Support

    Hi there,

    How are you defining primary category?

    Does this help? https://generatepress.com/forums/topic/how-to-display-only-primary-category-on-blog-site/

    #773609
    Vish

    Hello!

    Q: How are you defining primary category?
    My Answer:
    In WordPress, if we select multiple categories for a post, only one can be ‘primary’ category.

    Primary Category

    I want only the displayed which is ‘primary’ to be displyed in the front end and not all of them. Is it possible?

    As for the link you had given: The link above has instruction to use the code in the below link:

    https://gist.github.com/jawinn/1b44bf4e62e114dc341cd7d7cd8dce4c#file-primary_category-php-L3-L43

    I added the code from above link via Code Snippets plugin. That doesn’t get the job done. Can you please tell me what else I should do?

    Thanks!

    #773938
    Tom
    Lead Developer
    Lead Developer

    The Primary Category feature comes from Yoast SEO.

    That code they provided is to display the primary category titles on a page. It’s not meant to change the output of your archives to only show primary categories.

    The pre_get_posts action might be a good starting point, but I’m not familiar enough with Yoast to know the exact code.

    It may be worth checking with their support to see if it’s something they’ve helped with before.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.