-1

I'm using the following as part of a shortcode I'm creating:

$loop = new WP_Query(array('post_type' => 'client', 'posts_per_page' => $limit, 'orderby' => $orderby)); 

    if($loop){
        $preoutput = '<div class="outer">';
        $postoutput = '</div>';
        while ($loop->have_posts()){
            $loop->the_post();  
            $output .= '<div class="box box-'.$columns.'"><h2>hello</h2>'.the_post_thumbnail(); 
            $output .= '<div class="text"><h2 class="entry-title"><a href="'.get_permalink().'">'.get_the_title().'</a></h2>'.get_the_excerpt().'</div></div>';  
            $finaloutput = $preoutput . $output . $postoutput;
        }
    }

However, the post thumbnail doesn't appear in the markup, it appears just at the top of the post - why would it do this?

1

You are using the_post_thumbnail, which directly outputs the thumbnail in an image tag. You need to use get_the_post_thumbnail instead, which returns the image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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