Site logo

Archived topic

Display Only Primary Category in Posts

3 replies · Started by Vish on January 2, 2019

Viewing posts 1–4 of 4

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.

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!

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.

This archived topic is closed to new replies.