Show primary category title using Posts element with Yoast

I’m using the Posts element and adding a label to show the category of each post. The majority of posts have to have multiple categories assigned. What I’d like is for the label to show the title of the primary category, which is a feature of Yoast.

I tried unsuccessfully to do this by using a nested dynamic content string with the meta key Yoast has to get the ID of the primary category:

{{dc:term:title term="{{dc:term:meta key=’_yoast_wpseo_primary_category’}}"}}

Is there another way to achieve this?

Hello Marina,

Thanks for writing in! The only way you can display a single category of the post is to use this: {{dc:term:name}}. Regretfully the Yoast’s Primary Category feature is not supported with the dynamic content. It may need custom development which is beyond the scope of our support already.

Best Regards.

I was running into the same problem. You can add this shortcode solution into your child theme’s functions.php file: https://gist.github.com/geekysihag/97938e6e8e318d0ab59b437f44b8b6f1

Once you’ve done that, you can use the shortcode [yoast-primary-category] within a text element to call the shortcode and have it display where you want it to.

To style it, go to your global css file in Appearance then Customize. Add the CSS class span.post-category a {}
to your stylesheet and style as needed.

This is the only way I’ve found to force the layout template to play nice with the yoast primary category. Hope this helps!

1 Like

Hello Sherri,

Thanks for sharing the information.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.