Advertisement
shelob9

Untitled

Aug 1st, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. /*
  2. Plugin name: Caldera Terms shortcode
  3. */
  4. function caldera_terms_shortcode_callback( $atts ) {
  5.     $atts = shortcode_atts(
  6.         array(
  7.             'taxonomy' => '',
  8.             'post' => get_the_ID(),
  9.         ),
  10.         $atts,
  11.         'my_terms'
  12.     );
  13.  
  14.     if ( ! empty( $atts[ 'taxonomy']) ) {
  15.         $terms = wp_get_object_terms( get_the_ID(), $atts[ 'taxonomy' ] );
  16.         $out = '<ul class="my-terms-shortcode-term-list ' . esc_attr( 'my-terms-shortcode-term-list-' . $atts[ 'taxonomy' ] ) .'">';
  17.         foreach( $terms as $term ) {
  18.             $out .= '<li><a href="' . get_term_link( $term->slug, $atts[ 'taxonomy' ] ) . '">' . esc_html( $term->name ) . '</a></li>';
  19.         }
  20.         $out .= '</ul>';
  21.  
  22.         return $out;
  23.     }
  24.  
  25. }
  26. add_shortcode( 'caldera_terms', 'caldera_terms_shortcode_callback' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement