Advertisement
srikat

Untitled

Feb 11th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. add_shortcode( 'post_tags_plus', 'sk_post_tags_shortcode' );
  2. /**
  3. * Produces the tag links list with each link wrapped in span.tag-slug..
  4. *
  5. * Supported shortcode attributes are:
  6. * after (output after link, default is empty string),
  7. * before (output before link, default is 'Tagged With: '),
  8. * sep (separator string between tags, default is ', ').
  9. *
  10. * Output passes through 'genesis_post_tags_shortcode' filter before returning.
  11. *
  12. * @since 1.1.0
  13. *
  14. * @param array|string $atts Shortcode attributes. Empty string if no attributes.
  15. * @return string Shortcode output
  16. */
  17. function sk_post_tags_shortcode( $atts ) {
  18.  
  19. $defaults = array(
  20. 'after' => '',
  21. 'before' => __( 'Tagged With: ', 'genesis' ),
  22. 'sep' => ', ',
  23. );
  24. $atts = shortcode_atts( $defaults, $atts, 'post_tags' );
  25.  
  26. // $tags = get_the_tag_list( $atts['before'], trim( $atts['sep'] ) . ' ', $atts['after'] );
  27.  
  28. $tags = get_the_tags();
  29.  
  30. //* Do nothing if no tags
  31. if ( ! $tags )
  32. return;
  33.  
  34. foreach( $tags as $tag ) {
  35. // Get the ID of this tag
  36. $tag_id = $tag->term_id;
  37.  
  38. // Get the URL of this tag
  39. $tag_link = get_tag_link( $tag_id );
  40.  
  41. $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="tag"';
  42.  
  43. $tags .= '<a href="' . esc_url( $tag_link ) . '" class="' . $tag->slug . '" '. $rel .'>' . $tag->name . '</a>' . $atts['sep'];
  44. }
  45.  
  46. $tags = rtrim( $tags, $atts['sep'] );
  47.  
  48. $output = sprintf( '<span %s>', genesis_attr( 'entry-tags' ) ) . $atts['before'] . $tags . $atts['after'] . '</span>';
  49.  
  50. return apply_filters( 'genesis_post_tags_shortcode', $output, $atts );
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement