Support » Fixing WordPress » add_image_size() not adding new sizes to media upload area

  • I have the following code in my functions.php file and am only running the akismet plugin, but the new image sizes are not showing up in the media upload area.

    // Post Thumbnail Support
    	if (function_exists('add_theme_support'))
    		set_post_thumbnail_size(1280, 640);
    		set_post_thumbnail_size(640, 320);
    		set_post_thumbnail_size(160, 80);
    	// Add new image sizes
    	if (function_exists('add_image_size'))
         	add_image_size('Portfolio Thumbnail', 160, 80, TRUE);
         	add_image_size('Portfolio Large', 1280, 640, TRUE);
         	add_image_size('Portfolio Featured', 640, 320, TRUE);
         	add_image_size('Self Portrait (about sidebar)', 200, 233, TRUE);
Viewing 10 replies - 1 through 10 (of 10 total)
  • Thumbnails are only generated once (upon upload). So, any already-uploaded images will not be impacted by adding new add_image_size() calls.

    You will need to regenerate your Thumbnails, e.g. using the Regenerate Thumbnails Plugin.

    It doesn’t show up with new image additions either. I am also able to just delete all images uploaded already since this site is still in development. In other words, I started all over, and still there aren’t any new images sizes showing up in the media area. Any other ideas?

    Two other problems with your code:

    1) You call set_post_thumbnail_size() three times. This function should only be called once. Each successive time simply overwrites the previous call (and I don’t know what, if any, unintended consequences may result from multiple calls to this function).

    2) I believe the first argument in the call to add_image_size should contain no spaces. Try using characters aA-zZ0-9-_ only. Try changing e.g. Portfolio Thumbnail to portfolio-thumbnail, and e.g. Self Portrait (about sidebar) to self-portrait-about-sidebar.

    Correct of first point. I had messing around with different sizes just to see how crop worked, etc. and forgot to comment out two of them. This doesn’t fix it though. Already tried the using ‘-‘, e.g. portfolio-thumbnail as the first param, but that doesn’t fix it either. Going to go back through my functions.php file and remove some things to see if have some incorrect code or there’s something else going on. I’ve added quite a few items to the admin area… several custom post types, meta areas, etc.

    thanks for the assistance. if there’s anything else you can think of, please let me know.

    Why not just use the three sizes you can set in Settings > Media

    Add a code check to stop these from being changed:

    //Check and Set the Default Thumbnail Sizes

    Then they can be called with get the post thumbnail

    get_the_post_thumbnail($id, 'thumbnail');     // Thumbnail
    get_the_post_thumbnail($id, 'medium');        // Medium resolution
    get_the_post_thumbnail($id, 'large');         // Large resolution
    get_the_post_thumbnail($id, array(480,240) ); // Other resolutions



    Or Just:

    if (function_exists('add_theme_support'))
    set_post_thumbnail_size(1280, 640);


    get_the_post_thumbnail($id, array(160,80) );
    get_the_post_thumbnail($id, array(640,320) );
    get_the_post_thumbnail($id, array(1280,640) );



    because that’s about 11 lines of code when I only should need 4.

    You can set them without code from settings > Media then it is only one line to call the three different sized thumbnails?


    Actually, it was working the entire time. I was thinking I would see a size option (in addition to thumbnail, medium, and large in the media area), but that’s actually not the case. If I use the following (for example) the correct size is output…

    if (has_post_thumbnail()) : ?>
         <div id="featured-image">
              <?php the_post_thumbnail('Portfolio Featured', array('alt' => 'featured image icon', 'class' => 'alignleft')); ?>
    <?php endif; ?>

    Wow, I feel dumb. Sorry guys, and thanks for the input!

    Thanks Chip, that’s exactly what I needed.


Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘add_image_size() not adding new sizes to media upload area’ is closed to new replies.