Created
January 27, 2022 06:55
-
-
Save AchalJ/16ece692aa359058fdbe539165ed0b26 to your computer and use it in GitHub Desktop.
Shortcode to get taxonomy term description
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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