Advertisement
chris_di

Category & Tag Description Shortcode

Jan 8th, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. // Shortcode fpr Category & Tag Desc
  2. add_shortcode('cat_desc', 'cat_desc_shortcode');
  3. function cat_desc_shortcode( $atts, $content = null ) {
  4.     $a = shortcode_atts( array(
  5.         'id' => null,
  6.         'slug' => null,
  7.         'title' => 'false',
  8.         'link' => 'true',
  9.     ), $atts );
  10.  
  11.     if( $a['id'] ) {
  12.         $cat = get_category( $a['id'] );
  13.         $a['title'] = 'true';
  14.     } elseif( $a['slug'] ) {
  15.         $cat = get_category_by_slug( $a['slug'] );
  16.         $a['title'] = 'true';
  17.     } else {
  18.         $cat = get_the_category()[0];
  19.     }
  20.  
  21.     if( $cat == null ) return;
  22.  
  23.     $cat->url = get_category_link( $cat->term_id );
  24.  
  25.  
  26.     $output .= '<div class="description">'.$cat->description.'</div>';
  27.     return $output;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement