Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom image sizes not being generated. WordPress

  • SOLVED

I used to upload an image and wordpress would create the image sizes for my theme. Since I upgraded to 3.5 it no longer works. Wordpress only generates the image sizes set in media options. I can check this by simply checking the uploads folder and seeing the sizes of images that have been made.

Here's is my function that used to work. Has something changed in the new version of wp that stops the custom sizes being made.

I prefer to code solutions and not use plugins please.

//BEGIN Activate Thumbnails
if ( function_exists( 'add_theme_support' ) )
add_theme_support( 'post-thumbnails' );

set_post_thumbnail_size( 615, 9999);
add_image_size( '100-thumb', 100, 100);
add_image_size( '300-thumb', 300, 200 );
add_image_size( '455-thumb', 455, 9999 );

Answers (3)

2013-03-16

Fahad Murtaza answers:

set_post_thumbnail_size( 615, 9999);

if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'thumb-100', 100, 100);
add_image_size( 'thumb-300', 300, 200 );
add_image_size( 'thumb-455', 455, 9999 );
}

add_filter('image_size_names_choose', 'my_image_sizes');
function my_image_sizes($sizes) {
$addsizes = array(
"thumb-100" => __( "100 pixels"),
"thumb-300" => __( "300 pixels"),
"thumb-455" => __( "455 pixels")
);
$newsizes = array_merge($sizes, $addsizes);
return $newsizes;
}


For thumbnail resizing, you can use the following code (optionally)

update_option('thumbnail_size_w', 615); // update thumbnail width
update_option('thumbnail_size_h', 999); // update thumbnail height, unlimited here in this case to keep the aspect ratio
update_option('thumbnail_crop', 0); // no cropping


Also make sure you have the following in functions.php

if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' ); // The important part
set_post_thumbnail_size( 615, 9999 ); // default Post Thumbnail dimensions
}


Fahad Murtaza comments:

@David Gwyer: I second that, as evident from my code above.


julesphoto comments:

Thanks Fahd! That fixed it! Please can you just explain what you mean by this:

update_option('thumbnail_size_w', 615);

update_option('thumbnail_size_h', 999);

update_option('thumbnail_crop', 0);


Fahad Murtaza comments:

That is to fiz the thumbnail width and height and the last line is to set crop to none. 1 would mean cropping is active.

2013-03-16

Daniel Yoen answers:

you can try Hard Crop mode

add_image_size( '100-thumb', 100, 100, true);

add_image_size( '300-thumb', 300, 200, true);

add_image_size( '455-thumb', 455, 9999, true);

2013-03-16

David Gwyer answers:

Try having letters before numbers such as:

add_image_size( 'thumb-100', 100, 100);

Even if it doesn't fix the problem, it's a good practice.