WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
share|improve this question

marked as duplicate by brasofilo, toscho Jan 28 '13 at 11:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 1 down vote accepted

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.

share|improve this answer
Thanks bro! Worked fine :) – Chead Jan 28 '13 at 13:50

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