Skip to content

Instantly share code, notes, and snippets.

@AchalJ
Created January 27, 2022 06:55
Show Gist options
  • Select an option

  • Save AchalJ/16ece692aa359058fdbe539165ed0b26 to your computer and use it in GitHub Desktop.

Select an option

Save AchalJ/16ece692aa359058fdbe539165ed0b26 to your computer and use it in GitHub Desktop.
Shortcode to get taxonomy term description
// Using product_brand taxonomy in this example.
add_shortcode( 'product_brand_desc', function() {
if ( ! is_single() ) {
return;
}
$current_post_terms = wp_get_post_terms( get_the_ID(), 'product_brand', array( 'fields' => 'ids' ) );
$desc = '';
if ( ! is_wp_error( $current_post_terms ) && ! empty( $current_post_terms ) ) {
$current_post_term = $current_post_terms[0];
$desc = get_term_field( 'description', $current_post_term );
}
return $desc;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment