Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want the featured image of a post to display not only in the blog list view, but also inside the post (when i press "Read More..."). How do i do that?

I pasted this

if ( has_post_thumbnail() ) { 
 the_post_thumbnail('full');
} 

in single.php just before the_post();. It looks like this:

while (have_posts()) {
    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
      the_post_thumbnail('full');
    } 
    the_post();
    get_template_part('content', 'single');
}

But the image shows up, above the title. How do i make it show after the title, just like in the blog list view?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

@PatJ's answer affords the most control over the placement of the image but involves editing the theme, which may or may not be wise, or possible, depending on the circumstance, so an alternative is to add a filter to the_content.

function add_thumb_wpse_100914($content) {
    // check that we are on a 'single' post display and...
    // check if the post has a Post Thumbnail assigned to it.
    if ( is_single() && has_post_thumbnail() ) { 
      $content = get_the_post_thumbnail(null,'full').$content;
    } 
    return $content;
}
add_filter('the_content','add_thumb_wpse_100914');
share|improve this answer
    
Where exactly do i paste this code? –  koukouloforos May 27 '13 at 17:51
    
@user33351 in functions.php of your current theme –  Ravs May 27 '13 at 17:51
    
Well, now the image does show up inside the post, but it has a side effect. The image shows twice in the blog list view. How can i fix that? –  koukouloforos May 27 '13 at 17:57
    
You can put that in functions.php, in a plugin file, or in a must-use plugin. To fix the double image in the blog list, add an is_single condition. I'll edit the answer. –  s_ha_dum May 27 '13 at 17:58
    
Very nice! Thanks man. That is exactly what i wanted. :) –  koukouloforos May 27 '13 at 18:00

There should be a file in your theme called content-single.php (if it's not there, look instead for content.php). Inside that file there will be a line like the_title(). If you put your the_post_thumbnail( 'full' ); after that line, it should appear after the title in the single page view.

Rationale

the_post() sets up the data for the next post in The Loop (in the case of a single page, it sets up the post/page). The next line in your single.php -- get_template_part() -- is where the post/page view is actually assembled; it should contain the_title(), the_content(), etc.

References

Codex:
the_post()
get_template_part()
the_title()

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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