Support » Themes and Templates » the_post_thumbnail size not working

  • Okay, this is weird. I have the same code in two places. In my archive.php template, the thumbnails render at the proper size, and on a page with a custom query (every other part of the loop is working fine), they render at FULL size. No matter what I try as the size, they always show at the original upload size (no image size added to the src URL).
    Here’s the code I’m using inside the loop.

    <?php the_post_thumbnail( 'medium', array('class' => 'alignleft') ); ?>
    I’ve substituted ‘medium’ for ‘thumbnail’ or ‘large’ and nothing happens.

    I’ve checked my theme support, regenerated thumbnails, tried just the_post_thumbnail(); and nothing has changed. Meanwhile, the exact same loop works perfectly on a different template. Any help would be much appreciated.

Viewing 10 replies - 1 through 10 (of 10 total)
  • What theme are you using? Can you post the custom query you’re using to Pastebin and post the link here?

    Thread Starter jmaurer


    Hi Stephen, thanks for responding!

    I’m building my own theme (started out with the Bones starter theme).

    The query I’m using is for a custom post type. In the setup for this post type, I have 'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes' ). Are there any features I’m missing from this list to be able to resize the thumbnails?

    Here is a link to the pastebin where I’ve pasted the loop I’m using.

    I can’t seem to reproduce your issue. Can you temporarily enable debugging and see if any error messages occur?

    Thread Starter jmaurer


    I’ve been developing with Debug enabled and don’t have any errors. I just tried to manually set the size like so, the_post_thumbnail( array(100,100)); and it still doesn’t change the image. However, it DOES add a class to the image. Here are the results of this function:

    <img src="" class="attachment-100x100 wp-post-image" alt="image">

    DING DING DING! I just realized something important here. These images (I didn’t make them) are all pngs! Is WordPress incapable of creating thumbnails for pngs? Just looked in my uploads folder, and sure enough, the thumbnails exist for all of my jpegs, but no thumbnails for pngs.

    Unfortunately, I just uploaded a completely new PNG to my local install and WordPress created the thumbnails correctly.

    If you create an entirely new post of your custom post type and select a completely new JPG (one that’s never been in your media library) for the featured image, does WordPress create the thumbnails correctly? Make sure you’ve got a named size instead of the array for the_post_thumbnail().

    Thread Starter jmaurer


    Doh! PNGs are working for you??

    If I use a JPG as the featured image, it apparently works like a charm. Don’t know how I didn’t notice they were all PNGs before. Anyway, yeah. WordPress is not liking my PNGs…

    If they don’t contain anything personal and they aren’t too problematic, could you post one of the PNGs to some place like Imgur? I’d like to try one of the images for myself?

    Thread Starter jmaurer


    Sure thing. Here ya go.

    The PNG you posted works for me. Can you run phpinfo() and see if php_gd has PNG support, and if so, what version of libPNG you’re running? Also, does it work if you switch to the default Twenty Fifteen theme? Does it work if you have all of your plugins disabled?

    Thread Starter jmaurer


    Okay, so I think I might have a clue to what’s going on here.

    I added a function a while ago that removes the set height and width from the <img> tags. I’m thinking that WordPress might be “faking” the resizing of PNGs with the width and height settings. Does that sound likely?

    Here’s the code I’m using to remove these attributes.

    add_filter( 'post_thumbnail_html', 'remove_width_attribute', 10 );
    add_filter( 'image_send_to_editor', 'remove_width_attribute', 10 );
    function remove_width_attribute( $html ) {
    	$html = preg_replace( '/(width|height)="\d*"\s/', "", $html ); return $html;

    I’ll be able to get back with more info either tonight or tomorrow.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘the_post_thumbnail size not working’ is closed to new replies.