How to Add Additional WordPress Image Sizes

How to Add Additional WordPress Image Sizes

You can add as many individual image sizes to your WordPress site as you like by using the following function.

Add the following code to your functions.php file of the theme you wish to use the custom image sizes for.

if ( function_exists( 'add_image_size' ) ) {
	add_image_size( 'my-custom-image1', 400, 9999 ); //400 pixels wide (and unlimited height)
	add_image_size( 'my-custom-image2', 320, 250, true ); //(true means the image will be cropped)

Your custom image sizes won’t show up in your media settings, or your post edit screen, but it will be usable when calling a post thumbnail via PHP, like so:

<?php echo get_the_post_thumbnail($post->ID, 'my-custom-image1'); ?>

Related Links:

WordPress Hosting

Leave a Reply

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