2

In my theme has one shortcode tags to display tags of post and function to load content post. But in function doesn't include shortcode tag. Now I want to add it to function but i don't know how to do it. Hope everyone help me out. Thank in advance.

Shortcode tag

function wwl_post_tags( $atts ) {
    if( $tags = get_the_tag_list( '', ', ' ) ) {

        $defaults = array(
            'before' => __( 'Từ khóa: ', 'icy' ),
            'after'  => '. ',
        );
        $atts = shortcode_atts( $defaults, $atts );

        return sprintf( '%1$s<span class="entry-tags">%2$s</span>%3$s',
            $atts['before'],
            $tags,
            $atts['after']
        );
    }
}
add_shortcode( 'post_tags', 'wwl_post_tags' );

Function to load content post

function wwl_post_content() {
    global $more;

    if ( ! is_single() ) {
        $more = 0;  
    }

    do_action( 'wwl_before_post_content' ); // Hook

    if ( ! is_single() && of_get_option('post_content') == 2 || is_search() ) :
    ?>
        <div class="entry-summary">
            <?php wwl_thumbnail(); ?>
            <?php the_excerpt(); ?>
            <div class="clearfix"></div>
        </div><!-- .entry-summary -->
    <?php else : ?>
        <div class="entry-content">
            <?php wwl_thumbnail(); ?>
            <?php the_content( '', false, '' ); ?>
            <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'icy' ), 'after' => '</div>' ) ); ?>         
            <div class="clearfix"></div>
        </div><!-- .entry-content -->
    <?php endif;
}
  • 1
    Are you asking how to create a shortcode? Sorry. I really don't understand this question. – s_ha_dum Feb 11 '14 at 5:48
  • @s_ha_dum no bro, i wanna add shortcode tag into single post to display tags – Hung PD Feb 11 '14 at 5:59
4

Another option is to use the do_shortcode() function. This will make WordPress run the shortcode as if it was in the content editor.

So where you want your post tags to appear just put.

<?php echo do_shortcode('[post_tags]'); ?>
|improve this answer|||||
2

i wanna add shortcode tag into single post to display tags

Paste [post_tags] into your post body via the post editor on the backend.

See: http://codex.wordpress.org/Shortcode_API

If you want to do it automatically you could put a filter on the_content (untested):

add_filter(
   'the_content',
   function($content) {
     if (is_single()) 
      $content .= '[post_tags]';
     }
     return $content;
   }
);
|improve this answer|||||
  • i tried but nothing changed, should i add in entry-content? – Hung PD Feb 11 '14 at 6:42
  • You need to edit the question so that it is more clear =. – s_ha_dum Feb 11 '14 at 13:52
  • If by "entry content" you mean the big post edit box, then yes. "Paste [post_tags] into your post body via the post editor on the backend." – s_ha_dum Feb 11 '14 at 14:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.