Add Image Sizes to WordPress

Posted on: August 30th, 2012

Sometimes you just need to add an extra image size. Whether it’s because you need to get a specific thumbnail size for a post or because you want to add a special size for a special admin option, you can get it done in a snap.

Just open up your functions.php file and add something similar to the snippet below.

add_image_size( 'image_size_name', 300, 200, true ); //put this somewhere in your functions.php file

// then call it in index.php or whatever with the following
<?php if ( has_post_thumbnail() ) {
	the_post_thumbnail('image_size_name');
} ?>
// the if statement just makes sure you have a post_thumbnail

This is much easier than adding some hefty PHP to add it in any other way and I advise you to try it out.

If you want to take it a step further, and add this new size to the media uploader image options, you can use the following code, taken directly from here.

function custom_wmu_image_sizes($sizes) {
        $myimgsizes = array(
                "image_size_name" => __( "Image Size Name Display" )
                );
        $newimgsizes = array_merge($sizes, $myimgsizes);
        return $newimgsizes;
}
add_filter('image_size_names_choose', 'custom_wmu_image_sizes');

// again, just stick this in functions.php

If you don’t like that method, you can also check out WPTuts.

Once you’ve added your sizes, the new sizes won’t take hold with your older images. But you can regenerate those images with a nifty little plugin called Regenerate Thumbnails by Viper007Bond.

Tags: , , ,

previous post: Regenerate Thumbnails next post: AE Tutorial – Punch Out Text