Cropped featured image in WordPress

It may be a featured image on the front end, but is post_thumbnail when it comes to back end and actually implementing it into the site. Adding cropped featured image in WordPress is quite easy though. First you need to add featured image support to your website (make sure to add it to after_setup_theme hook) – needless to say you would add it to functions.php:

PHP

1

add_theme_support('post-thumbnails');

Let’s assume that you already chosen featured image dimensions (on either posts or pages). Now you want to crop whatever user uploaded to fit your container. Therefore you may want to add your custom size:

PHP

1

add_image_size('page-featured-image',1110,400,true);// (cropped)

True means that you enabled hard cropping function. You can also fine-tune the cropping function if using an array (start cropping from left, center, or right, for example). You will find about its detailed use within code reference (check the link below).

So the full code that goes into functions.php would be something like:

1

2

3

4

5

6

7

functionbbird_under_setup(){

// Add Featured image sizes

add_theme_support('post-thumbnails');

add_image_size('page-featured-image',1110,400,true);// (cropped)

}

add_action('after_setup_theme','bbird_under_setup');

And this is how you call it (must be within the loop) on your page or post template: