Add New Featured Image Sizes To WordPress

By default, every image uploaded via WordPress Media manager will be uploaded to different sizes. However, when displaying them as featured image, the image need to be re-sized or cropped to get the desired size. This code should go in your functions.php file of your child theme (Yes, I strongly recommend you to use child theme to make any customization to your theme).

Here is the parameter you need to register a new size of featured image:
For more details, see the WordPress codex.

1 2 3 4 5 6 7
<?php
// Add new featured image size
add_image_size( $name, $width, $height, $crop );
?>
view raw functions.php hosted with ❤ by GitHub

The last parameter, $crop is should be set to TRUE for hard cropping. By default, it return false.

Here are some examples:

1 2 3 4 5 6 7
<?php
// Add new featured image sizes
add_image_size( 'grid-thumbnail', 236, 157, TRUE );
add_image_size( 'single-post-thumbnail', 236, 236, TRUE );
add_image_size( 'video-small', 110, 73, TRUE );
view raw functions.php hosted with ❤ by GitHub

Comments

Trackbacks

Leave a Reply

Your email address will not be published. Required fields are marked *