Change defined sizes of WordPress post images afterwards

WordPress themes define a fixed size for featured images, to which the images are cut and displayed. This post explains how you can change the size of WordPress post images later.

Changing the image sizes is possible with a little code in a child theme or with the help of plugins.

Change the size of the article image in the child theme

The first option is to overwrite the defined image sizes in a child theme . To do this, you have to find out the defined image sizes in the parent theme. Most of the time these are in the theme's setup function in functions.php.

The sizes of the standard featured images are usually defined with set_post_thumbnail_size() , additional image sizes are created with add_image_size() . My previous post explains the technical implementation of featured images in detail.

Example of image sizes in the parent theme:

 /** * Sets up theme and registers support for various WordPress features. */ function theme_slug_setup() { // Other Theme Setup code... // Enable support for Post Thumbnails on posts and pages. add_theme_support( 'post-thumbnails' ); // Set detfault Post Thumbnail size. set_post_thumbnail_size( 300, 200, true ); // Add custom image size for single posts. add_image_size( 'theme-slug-single-post', 800, 9999 ); } add_action( 'after_setup_theme', 'theme_slug_setup' );

The functions are smart enough to handle multiple image sizes with the same name. So there is no error, but the last defined image size is used.

We can make use of this mechanism by simply redefining the image sizes in the child theme, thereby overwriting the sizes of the parent theme.

 /** * Change Image Sizes from Parent Theme. */ function child_theme_change_image_sizes() {   // Change detfault Post Thumbnail size.   set_post_thumbnail_size( 1200, 800, false );   // Override custom image size for single posts.   add_image_size( 'theme-slug-single-post', 600, 400, true ); } add_action( 'after_setup_theme', 'child_theme_change_image_sizes', 11 );

Important: The functions.php of the child theme is loaded before the functions.php of the parent theme.

To ensure that our function in the child theme is loaded after the parent theme and that the image sizes are overwritten with our newly defined sizes, we set a priority of 11 for the after_setup_theme callback.

If the priority is not defined as in the first example, the default value 10 is used. With a priority of 11 or higher, we ensure that the function is executed after the setup function of the parent theme.

After changing the image size in the child theme, existing images must be regenerated .

Change WordPress featured image size with the Simple Image Sizes plugin

The second, simpler option without code and child themes is to use the Simple Image Sizes plugin.

This plugin allow create custom image sizes for your site. Override your theme sizes directly on the media option page.

From: Rahe

( 86 )
Last updated: 2 years ago
100,000+ active installs
Compatible up to: 4.9.16

After installing the plugin, new options are available under Settings → Media . In addition to the standard settings of the core for the image sizes, all additional image sizes can now also be changed, which are defined by themes and plugins.

With the plugin the width, height and cropping method of the existing image sizes can be changed. I really like the variety of options for precisely configuring the cropping mode. The plug-in can be used to determine exactly from which side or corner the images are cut (from top left to bottom right).

Incidentally, completely new image sizes can also be created, for example for inserting normal images in the articles.

Simple Image Sizes Plugin

If you want to keep your image sizes and deactivate the plugin, the plugin provides suitable PHP code for the defined image sizes, which you can copy into the functions.php of the child theme.

Here, too, existing images are not automatically adjusted for the new sizes. But the plugin provides extra options to regenerate the article images.

Regenerate article images

In my tests, changing the image sizes and regenerating the article images worked without any problems, so I can recommend the plugin without reservation.

Overview of all articles in this series