Add Image Sizes to WordPress

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.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

John Hartley is a Director of Product Engineering at Beam Dental in Columbus, OH. With 5+ years of leadership experience he has worked in startups, agencies, and began his career as a freelance Front End Developer. Always looking to iterate, this blog is a place for him to share his knowledge as well as hone his craft, challenge assumptions, and build a strong base of leadership and management knowledge. Connect with him on LinkedIn

0
Would love your thoughts, please comment.x
()
x