WordPress.org

Ready to get started?Download WordPress

Forums

the_post_thumbnail() is not displaying the default thumbnail (12 posts)

  1. I've noticed since WP version 3.2.1 that the_post_thumbnail() function no longer returns the default but instead displays the default image.

    The codex stipulates that one can use

    the_post_thumbnail();                  // without parameter -> Thumbnail
    
    the_post_thumbnail('thumbnail');       // Thumbnail (default 150px x 150px max)
    the_post_thumbnail('medium');          // Medium resolution (default 300px x 300px max)
    the_post_thumbnail('large');           // Large resolution (default 640px x 640px max)

    But this does not seem to be true anymore, the thumbnail only works when one uses the_post_thumbnail('thumbnail');

    I thought it was an error in my theme, but I just tried it with both 2011 and 2010 themes and I get the same result. Could this be a bug?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    the_post_thumbnail(); works fine for me.

  3. That is just so weird.

    I took everything out of my functions.php file and only kept:

    <?php
    add_theme_support('post-thumbnails');
    ?>

    in there.

    I inserted <?php the_post_thumbnail();?> in both my page and my post and don't see the thumbnail. The only way I can see the thumbnail is by using <?php the_post_thumbnail('thumbnail');?>

    If it's not the theme, what could be causing this?

    Here is the link to the said pages:

    Post

    Page

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Have you tried:

    - deactivating all plugins to see if this resolves the problem. If this works, re-activate the plugins one by one until you find the problematic plugin(s).

    - switching to the Twenty Eleven theme to rule out any theme-specific problems.

    - resetting the plugins folder by FTP or PhpMyAdmin. Sometimes, an apparently inactive plugin can still cause problems.

  5. Yes on both accounts. I deleted all plugins.. this site is just a test site and I tried both the Twenty Eleven and Twenty Ten themes with same results...

    I might try a fresh install on a client site and play with that. It's not that big of a deal since I can use <?php the_post_thumbnail('thumbnail');?> but it's just stumping me. I thought that perhaps it was a bug, but clearly it must be me. :(

  6. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Are you calling the post thumb outside of the Loop?

  7. No I'm not doing anything complicated. Perhaps I'm misunderstanding how this function is supposed to work. I just tried the following and got the same result:

    - Set up a fresh install of WordPress
    - Did NOT install any themes, plugin, change settings, inserted content.
    - Added a featured image to my sample page
    - The default theme, Twenty Eleven, displayed the image in the banner as it should.
    - I opened the content-page.php file and added <?php the_post_thumbnail(); ?> inside the loop, just above the <?php the_content();?> [I know I'm not supposed to do that, I'm suppose to use a child theme, blah blah, but I'm just trying to figure this out. ;)]
    - Once I do this, a large image shows up with this html -
    <img class="attachment-post-thumbnail wp-post-image" width="1000" height="288" title="IMGP1912" alt="IMGP1912" src="http://localhost:8888/thumbnail/wp-content/uploads/2011/10/IMGP1912-1000x288.jpg">
    - When I change the code to <?php the_post_thumbnail('thumbnail'); ?> I get the thumbnail and this code
    <img width="150" height="150" src="http://localhost:8888/thumbnail/wp-content/uploads/2011/10/IMGP1912-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="IMGP1912" title="IMGP1912" />

    So it seems to me that what the codex is saying:
    the_post_thumbnail(); // without parameter -> Thumbnail
    is wrong.

    Am I the only one that gets this?

  8. Eric Mann
    Member
    Posted 2 years ago #

    Ir sounds like you somehow had a default overwritten.

    When WordPress calls the_post_thumbnail() without any arguments, it uses "post_thumbnail" as the default size ... not "thumbnail."

    It sounds like your sizes for "thumbnail" are correct (since you can get the_post_thumbnail('thumbnail') to work) ... but you site isn't recognizing "post_thumbnail" as a valid size.

  9. I'm not sure how the default could have been overwritten.
    I did some more testing right now and installed a new WordPress site on my Dreamhost account instead of localhost.

    I tried using the_post_thumbnail() using Chris Coyier's blank theme and same result. To display the thumbnail size, I need to use the_post_thumbnail('thumbnail');

    It's no biggie, but I do think that there is a bug. I'll just teach my students to use the_post_thumbnail('thumbnail'); to be safe.

  10. curtismchale
    Member
    Posted 2 years ago #

    I just looked at a fresh install I have of WordPress locally and I'm getting the same results as Christine. If I just use the_post_thumbnail I'm getting a 200X200 image (the size I uploaded). If I add the 'thumbnail' argument I get the 15X150 image. I tried it on Twenty Eleven.

  11. Thanks Curtis, Glad to hear it's not just me.

  12. curtismchale
    Member
    Posted 2 years ago #

    I just took a deeper look at the code and while the comments say it defaults to the 'thumbail' argument Eric is right is doesn't actually, it uses the 'post-thumbnail' argument. I just uploaded a huge image (3000X2000) and if I just call the_post_thumbnail it gives me a slightly cropped version but it still overflows the side content.

    For Twenty Eleven it appears to be because they're also using the set_post_thumbnail function and setting the default post thumbnail size to match what they want for the header image. I'm guessing that this would be the same for Twenty Ten (of course I'm too lazy to look). When I remove the header image values and set it to 150, 150 I get an image that's the proper 150 by 150. When I set the media thumbnail size to 100px it has no effect on the generated image.

    I admit I can't think of a time I haven't needed to generate my own image sizes and I call them with their name so I might be missing how the post thumbnail function is supposed to work but it would seem to me that the end user should be able to change the size of it with the media settings as long as it's called with the function and no arguments.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags