Skip Navigation

[Resolved] Yoast primary taxonomy : displaying something else than the ID

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by xavierC-2 6 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#536970

Hi,

I use this shortcode : [wpv-post-field name='_yoast_wpseo_primary_category']
It displays the ID of the category set as primary.

How can I display the name (title) of the category rather than its ID ?

Thank you for your help.

#537076

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - you can use custom shortcode to display yoast primary category.

For example - add following code to your theme's functions.php file.:

function func_get_yoast_primary_category( $atts ) {
          global $post;
         $cat_id = get_post_meta($post->ID, '_yoast_wpseo_primary_category',true);
          $term = get_term( $cat_id );
	  return  $term->name; 
	
}
add_shortcode( 'get_yoast_primary_category', 'func_get_yoast_primary_category' );

#537238

Hi Minesh,

thanks!

Then I just have to use the shortcode [get_yoast_primary_category] and it works! 🙂

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.