Support » Theme: Seasonal » post-thumbnail image size doesn't exist

  • in inc/template-tags.php, #74:

    if ( is_singular() ) :
    	?>
    
    	<div class="post-thumbnail">
            <?php the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title(), 'itemprop' => "image")); ?>
    	</div><!-- .post-thumbnail -->
    
    	<?php else : ?>
    
    	<a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
    		<?php
    			the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title(), 'itemprop' => "image"));
    		?>
    	</a>
    
    	<?php endif; // End is_singular()

    post-thumbnail is not a valid size. Please add
    add_image_size ( "post-thumbnail", 980, 980, false );

    ( or a size you believe to fit ) to your theme’s code, tied to add_action (‘init’) of WordPress.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Theme Author Shaped Pixels

    (@shaped-pixels)

    Actually, it does not require a predefined thumbnail size. The code I used is similar in the twentysixteen theme, such as this snippet which does not have an add_image_size set:

    if ( is_singular() ) :
    ?>
    <div class="post-thumbnail">
     <?php the_post_thumbnail(); ?>
    </div><!-- .post-thumbnail -->
    
    <?php else : ?>
    <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
    <?php the_post_thumbnail( 'post-thumbnail', array( 'alt' => the_title_attribute( 'echo=0' ) ) ); ?>
    </a>

    Then mine:

    if ( is_singular() ) :
    ?>
    <div class="post-thumbnail">
    <?php the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title(), 'itemprop' => "image")); ?>
    </div><!-- .post-thumbnail -->
    
    <?php else : ?>
    <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
    <?php the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title(), 'itemprop' => "image")); ?>
    </a>

    The thing is, if you remove the ‘post-thumbnail’ with an array, you get a “Undefined offset” error.

    The problem it causes that since WP 4.4, there are responsive images, and if you add a size without a top limit, it’ll use the original as max size – which, in some cases, are full sized DSLR images, 30-40MB per file, which is wrong.

    Theme Author Shaped Pixels

    (@shaped-pixels)

    dimensional size doesn’t always relate to file size. Whenever you upload photos in a website, or using photos in a design, no one should be uploading the full sized un-optimized image, such as 30-40 MB images. Images should be cropped, sized, and/or optimized first. The only exception would be if you are making a raw image available for download as an actual file.

    ??

    dimensional size doesn’t always relate to file size.

    Hell it does. It may not be linear but unless you’re referring to vector graphics, of course it does.

    Whenever you upload photos in a website, or using photos in a design, no one should be uploading the full sized un-optimized image, such as 30-40 MB images. Images should be cropped, sized, and/or optimized first. The only exception would be if you are making a raw image available for download as an actual file.

    … which is exactly the case when a photographer is selling pictures online. You’d also expect that WP is taking care of the resize, since it had been part of it for about a decade.

    This is a bug.. Use large instead of post-thumbnail
    if you don’t want to add fixed sizes.

    Theme Author Shaped Pixels

    (@shaped-pixels)

    …could use “large”. But if someone blanks out their media settings (for sizes), putting “large” in place of “post-thumbnai” is the same thing except it’s named differently and either one still references the original image size. So if the media settings are blanked out, there’s no size reference other than the original uploaded image dimensions.

    Plus, here is a snippet from the Codex:

    If your theme enables Post Thumbnails then “post-thumbnail” is also available and this is the default when using Post Thumbnails.

    And to reiterate, you do not use 30-40 MB images in a post (or even a 1 MB one). In a case of a photographer, if they make images available as file downloads, this is something different.

    that name is ‘thumbnail’. There is no ‘post-thumbnail’.

    Use this to print the available image sizes in any WordPress; I recommend a fresh one, without plugins.
    https://codex.wordpress.org/Function_Reference/get_intermediate_image_sizes

    This is what I’m trying to tell you: you are referencing a nonexistent intermediate image size identifier, “post-thumbnail”. You either need to reference an existing or create this.

    add_image_size()

    Theme Author Shaped Pixels

    (@shaped-pixels)

    Well, you should pass that info on to the theme review team and the core team, especially to the ones who make the default WP themes.

    Twenty Fifteen:

    the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) );

    Twenty Sixteen:

    the_post_thumbnail( 'post-thumbnail', array( 'alt' => the_title_attribute( 'echo=0' ) ) );

    I believe even though ‘post-thumbnail’ is also available as default, it generates no error if used in the way as the default themes, my theme, and many others have.

    However, if you feel this is incorrect, you should bring this up to the core team. Perhaps the Codex also needs updating as well. If this method is indeed not valid, then everyone needs to know so that everyone can correct it and to also have it changed in the default themes…but to also have the theme review team be aware to check that in every review they perform.

    Theme Author Shaped Pixels

    (@shaped-pixels)

    Actually, I will go in and ask them to confirm what you brought up and will follow up here with what they respond with.

    No, it does not generate error. It falls back to the full sized original image. That is the problem.

    And yes, those are all wrong and I will report it; meanwhile, you could consider fixing it.

    https://github.com/WordPress/twentysixteen/blob/master/functions.php#L385

    This is what your theme is missing.
    And this is one of the most horrifying hack I’ve seen in WordPress.

    Theme Author Shaped Pixels

    (@shaped-pixels)

    For your last post…you should chat with the core team then if WordPress is doing something they shouldn’t.

    Anyway, back to your original topic at hand. I did some follow up to this. In a sense, we’re both correct. However, I do need to add set_post_thumbnail_size(width,height,crop) to my functions.

    So on the next update, I will need to do that…which is what the two default themes did.

    Could you tell me why not the add_image_size solution?
    That way you’re not overwriting media settings set by the user.

    Theme Author Shaped Pixels

    (@shaped-pixels)

    That one I didn’t ask.
    But you don’t always have to do add_image_size unless you need every image uploaded to generate an extra thumbnail in whatever size you need. In one of my themes, i have a grid layout but I need a specific size generated, so I used add_image_size to the functions file for that.

    I’m one who likes to blank out the media settings. I do not like WP creating thumbnails when I never use them and having it fill up disk space; I’d rather create what I need first, then upload them as needed.

    OK. If it solves the problem of responsive images falling back to the max size without upper limits, the method doesn’t really matter, but it needs fixing.

    Theme Author Shaped Pixels

    (@shaped-pixels)

    on the next update.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘post-thumbnail image size doesn't exist’ is closed to new replies.