If you are looking for additional image sizes then you are aware of default WordPress’s four images sizes
But additional image sizes are important according to the purpose of design that helps to look better and perform well on WordPress sites.
In this article we will help to create additional image sizes.
Add following code in your active theme’s functions.php for the support of post thumbnails.
With this code you are able to register addition images sizes as shown in the example below:
From the above example you see three different images sizes that have different modes such as hard crop,soft crop and unlimited height.
As you notice from the above example there is a “true” argument after the height.
True argument cropping position is centered but if you have another purpose for cropping images size then you can use array ( ‘horizontal-position’, ‘vertical-position’ ).where
- Horizontal-position accepts: ‘left’, ‘center’, or ‘right’.
- Vertical-position accepts: ‘top’, ‘center’, or ‘bottom’.
Soft crop mode
As shown in example you don’t see additional value added after height.By default mode is turned on, It has value of false.
If you only specify the width, the image will be as long as it needs to be to keep the proportions
Unlimited height mode
If we are planning an infographics page then this method is useful for long and full of information.
By specifying width while leaving the height to be unlimited is best practise for good look of the page.
Displaying additional image size in your frontend
Now your desired image size can be displayed to your theme’s pages by pasting the following code:.
With this code you can display image size with the styling that looks good as your need.
If you want to display one picture in particular, using one of your new sizes, use the following code:
Note: Specify your image ID in this case.
This is how you can create and display image size in your WordPress Theme.
But if you switch themes and want old images to regenerate then easy steps to regenerate thumbnails or new image size in wordpress using plugin.
Leave your comments below and let us know which update and feature you liked more. Also, subscribe to our newsletter. We send some awesome WordPress tutorials through our newsletter.