How to Add Custom Image Size in WordPress

Add Custom Image Size in WordPress. By default, WordPress automatically creates many models of image uploads in multiple sizes. Additionally, WordPress themes and plugins can also produce their own image size.

In this article, you will learn how to easily create custom image sizes in WordPress and use them on your website.

What Are Default WordPress Images Size?

By default, each WordPress installation appears with three custom image sizes.

Thumbnail – 150*150
Medium – 300*300
Large – 1024*1024

This indicates that when you upload an image to your website, the kernel will automatically generate models in those sizes. However, sometimes these dimensions are not the ones you want for your website.

Why Need to Create Additional Image Size in WordPress?

Normally, all Powerful WordPress themes and plugins manage image sizes very well. For example, your WordPress theme may create new sizes to use as thumbnails on archive pages. However, sometimes these image sizes may not fit your own necessities. You may need to use a different image size in a child theme or a post-grid layout.

You can do this by generating custom image sizes in WordPress and then calling these sizes whenever you want them.

Add Custom Image Size in WordPress Manually

With some words of PHP, you will be able to add custom image sizes to your WordPress site. As we’ll edit some core files before you start we advise you to create a child theme and generate a full backup of your site.

Adding Custom Image Sizes

Simply login to your WordPress Dashboard then, go to Appearance > Theme Editor.

By default, the theme editor will load the style.css file but to put additional image sizes you will require to select the functions.php of your child theme.

After you open the fuctions.php file, paste the following code.

add_theme_support( 'post-thumbnails' );

This single script will enable the add_image_size function on your installation. Without this, you won’t be ready to create any custom image sizes. After pasting the code, press the Update File button.

We have strongly enabled the function on your website. Now, require to add your preferred custom dimensions. For that, we’ll use the below code:

add_image_size( 'sidebar-thumb', 140, 140, true ); // For Sidebar Image 140*140px
add_image_size( 'homepage-thumb', 240, 240 ); // For HomePage Image  240*240px
add_image_size( 'singlepost-thumb', 600, 300 ); //  For single post Image  600*300px

That’s it! You have Successfully added additional image sizes to your WordPress site.

Every moment you upload an image and check the size option. Now, you will see that WordPress generates copies of the image in the new custom sizes. Additionally, you can use the Regenerate thumbnails plugin to create thumbnails of your images.

Create custom image size with plugins

If you don’t desire to edit your theme’s core files, you can add additional image sizes using plugins. Instead of editing the functions.php file, you can add custom code using two different tools/plugins. We’re using one of them to do this job.

Installing and Activating Code Snippets

From your WordPress Dashboard go to Plugins > Add new. Search for Code Snippets, install it, and activate it.

Then, Need to go to the snippet settings.

Adding Custom Snippet

To add new custom image sizes, you will require to create a new snippet.

add_theme_support( 'post-thumbnails' );

add_image_size( 'post-thumbnail size', 800, 240 );
add_image_size( 'homepage-thumb size', 220, 180 );
add_image_size( 'fullpage-thumb size', 590, 9999 );

After you add the code in the snippet section, Save it.

Leave a Reply

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