Post Thumbnail Custom Size In WordPress

Post thumbnail sometimes will be real problem for the design. If you are WordPress theme developer, you know what I mean.

You can’t force the theme user to adjust post thumbnail with Photoshop or other photo editors.

How To Adjust Thumbnail With Custom Size?

If you want to crop the thumbnail in theme, do the following.

Open your theme functions.php and add the following codes.

function hs_setup(){
    add_image_size('hs-blog-thumbnail', 600, 400, array('center', 'center'), true);
add_action('after_setup_theme', 'hs_setup');

The options in here tells the WordPress that how to treat with thumbnails.

600 is the width of the image, 400 is the height of the image.

array(‘center’, ‘center’) tells the WordPress that, display image in center from top and from left.

First one is the x_crop_position and accepts “left”, “center” or “right”.

The second is y_crop_position and accepts “top”, “center” or “bottom”.

The last option ( “true” ) tells the WordPress that, crop the image or not.

Use The Size

Go to the file that you display thumbnail and add the below code.


The Method Not Working On Old Thumbnails.

If you have images before the adding size, your images will not be crop. To add size to old thumbnails use Regenerate Thumbnails plugin.