See the updated and more complete post about image sizes in WordPress
WordPress 3.3 is finally out, and features a host of new improvements in the UI, along with other novelties.
A new feature I’m digging is the image_size_names_choose filter, which enables us to add new image sizes to the media upload/insert interface.
Check out the code below and the resulting screen:
if ( function_exists( 'add_image_size' ) ) { add_image_size( 'new-size', 300, 100, true ); //(cropped) } add_filter('image_size_names_choose', 'my_image_sizes'); function my_image_sizes($sizes) { $addsizes = array( "new-size" => __( "New Size") ); $newsizes = array_merge($sizes, $addsizes); return $newsizes; }
If you enjoyed this post, make sure to subscribe to WPMayor’s RSS feed.
35 Responses
Does this also work with old images?
It works only with the new images, but how to apply this to old images too?
Nice article, thanks for sharing such an informative article. Great work, keep sharing.
For more details related to wordpress development visit here .
My coder is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the costs.
But he’s tryiong none the less. I’ve been using Movable-type on a number of
websites for about a year and am concerned about switching to another platform.
I have heard excellent things about blogengine.net. Is there a way
I can transfer all my wordpress posts into it? Any help would be really appreciated!
Truly no matter if someone doesn’t know after that its up to other visitors
that they will assist, so here it occurs.
Predator X which has now been recognised as a species of Pliosaurus is actually bigger than the Dunkleosteus and with its
30 cm lengthy enamel and massive jaw would have been a formidable opponent for Large Daddy to should kill.
Follow link explains how to add custom size into wordpress media uploader
https://errorsflow.com/index.php/2016/07/21/custom-image-sizes-not-showing-media-uploader-wordpress/
Hello, take a look to this plugin -> https://demo.ad-theme.com/plugin/imager/
– it creates unlimited image sizes (cropped and not)
– it adds sizes on media select field
– it adds css filtering and animations
– it can manage watermarks
Bye
Hello Jean! First I want to thank you for this post, it’s working perfectly but I just can’t figure out how you can add multiple sizes. I need two, for landscape and portrait pictures and now I have set it up only for the landscape ones,
hello sir, how would you make so the size is width:100% and height is auto? thank you hope to hear from you soon
hi
I have put this code im my page. I want to apply this in plugins but I cannot select new size.
what is the problem with this. any idea ??
This is content of which file ? I can’t find it, so sad
Your theme’s functions.php file.
Thankyou very much !
Link fixed 🙂
i have 404 too again!
That’s strange cause I fixed it yesterday, can you tell me where that link is pointing to for you?
Nice post…. i really learn a lot …..thanks for nice post.
I have a problem:
add_theme_support(‘post-thumbnails’);
if (function_exists( ‘add_image_size’ ) ) {
add_image_size(‘Imagen_slider’, 960, 400, true);
add_image_size(‘Imagen_entrada’, 120, 120, true);
add_image_size(‘Imagen_Item_Area’, 150, 95, true);
}
}
add_filter(‘image_size_names_choose’, ‘size_mejorada_custom’);
function size_mejorada_custom($sizes) {
$addsizes = array(
‘Imagen_slider’ => __( ‘Versión grande para usarla en la portada’),
‘Imagen_entrada’ => __(‘Pequeña para los resúmenes.’),
‘Imagen_Item_Area’ => __(‘Icono para las entradas de Areas’)
);
$newsizes = array_merge($sizes, $addsizes);
return $newsizes;
}
When i tried to upload a picture with size 117 * 115
In the uploader i can select only
Miniatura
Medio
Grande
Tamaño completo (117 × 115)
Versión grande para usarla en la portada
Pequeña para los resúmenes.
Icono para las entradas de Areas (117 × 95)
Only i can select: Tamaño completo and Icono para las entradas de Areas. But it have not my custom size,
I use in the code:
the_post_thumbnail(‘Imagen_Item_Area’);
I think that i am using well the instructions.
Thanks for your help
thanks for the tip!
this works perfectly for me with WordPress 3.5
I have a custom image size ‘slider’ defined. 950px X 300 px. In the wp_options table ‘slider_w’ = 950 and ‘slider_h’ = 300. When trying to insert an image to a post the size for ‘Slider’ is shown as 590×186. Any thoughts on why this may be happening?
Thanks
Hi,
I tried but don´t work completely. I see the new size in the Media Edit but can select the new size and also doesn´ display the width and height, any idea ?
Thanx.
Have you gotten it to work pancho?
is there a way to add multiple new sizes?
Yes you can add as many sizes as you wish.
I tried the code and it generates the image in the upload folder but i don’t see the new option in the media upload screen. I’m using 3.3.1 this would be really useful for my client to able to choose image size based on location rather than dimension ie ‘main post’, ‘recent post’
many thanks
neil
This is fantastic, great article.
One thing, is there a way to have these custom image sizes show up in the “edit image” editor as well? So if I go to edit the photo in the uploader, when I go to crop it and apply, it only shows the wordpress defaults.
Hi.
i have created my new image size 300 x 100 like your example but if i upload an image with the same width and height i’m not able to select New Size but only Full Size.
Any help is appreciated!
Anaother question: Can we use this custom image size in gallerie now?
It should work as if it was a normal default wordpress size, so it should be usable in galleries too. There is also a great plugin called ‘Regenerate thumbnails’ which can be useful in combination with the code above.
Thanks for your answer.
it’s Ok, i did what i wanted!!
So, if the image was already uploaded, it seems to be KO, but if i upload a new image, it’s OK.
Thx for your help, it will be usefull!
Welcome 🙂
Hi, Thx for the tip, but, it doesn’t work on my website.
i pasted your code in my function file and when i want to insert a pic, i can see my new size without dimension, but i can’t select it…
Try saving the post first and then see if you can select it. Or else try uploading one first image through the media gallery. It should work from then onwards. It just needs to be initialised that first time. Let me know if you still have problems after having tried that.