Possible Duplicate:
The result of a shortcode appear BEFORE page content
short code output too early

I got this shortcode for display my blog posts on my page, but the EXCERPT and the COMMENTS are displaying on the top of my page. Anyone has any ideia why is doing that?

    /// Recent Blog Posts
add_shortcode('recent_blog_posts', 'shortcode_recent_blog_posts');

    function shortcode_recent_blog_posts($atts) {

            $str = '';
            $args = array( 'numberposts' => 3, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
            $postslist = get_posts( $args );

            foreach ($postslist as $post) : setup_postdata($post); 
                $str .= '<div id ="article-section-box2" class="span3">';
                                $str .= '<div id= "image1" class="image-arcticle">';     
                                $str .= get_the_post_thumbnail($post->ID, '');
                                $str .= '</div>'; 

                                $str .='<p class ="orange16-no-bold">'.get_the_title($post->ID,'').'</p>';
                                $str .='<p class="date">13 Feb 2012 - <h6 class="orange-title">'.comments_popup_link('0 Comments', '1 Comment', '% Comments').';</h6></p>';
                                $str .='<p class="article_text">'.the_excerpt("child_of=8d").'</p>';
                                $str .='</div>';

            return $str;

1 Answer 1


You use the function the_exerpt(), replace this with get_the_excerpt().
I don't know for sure, but you might need to use apply_filters('the_excerpt', get_the_excerpt()) to maintain the formatting in wich the_excerpt() is returned.

Try to use get_comment_reply_link instead of comments_popup_link.

both functions the_excerpt() and comment_popup_link() won't return values, but print it, wich cause te content to be displayed at the top op the page.


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