Custom image sizes in WordPress

Custom image sizes in WordPress

Default images in wordpress are thumbnail, medium, large, full. Default size of thumbnail is 150x150, medium is 300x300, large is 1024x1024 and full is default upload size. Wordpress allows to add more custom sizes. For this you have to add custom sizes in functions.php file with add_image_size function. Use below code to add more images sizes.

if (function_exists('add_theme_support')) {
    add_theme_support('post-thumbnails');
    add_image_size( 'custom-image-size-1', 320, 320 );
    add_image_size( 'custom-image-size-2', 400, 400 );
    add_image_size( 'custom-image-size-3', 600, 600 );
}

Get in your template with post loop

if ( have_posts() ) : while ( have_posts() ) : the_post();
the_post_thumbnail( 'custom-image-size-1' );
the_post_thumbnail( 'custom-image-size-2' );
the_post_thumbnail( 'custom-image-size-3' );
endwhile; endif; 

Also Read: Custom social media validations with validator jQuery
Also Read: Get posts by meta key and meta value in WordPress

Default images in wordpress are thumbnail, medium, large, full. Default size of thumbnail is 150x150, medium is 300x300, large is 1024x1024 and full is default upload size. Wordpress allows to add more custom sizes. For this you have to add custom sizes in functions.php file with add_image_size function. Use below code to add more images sizes.

if (function_exists('add_theme_support')) {
    add_theme_support('post-thumbnails');
    add_image_size( 'custom-image-size-1', 320, 320 );
    add_image_size( 'custom-image-size-2', 400, 400 );
    add_image_size( 'custom-image-size-3', 600, 600 );
}

Get in your template with post loop

if ( have_posts() ) : while ( have_posts() ) : the_post();
the_post_thumbnail( 'custom-image-size-1' );
the_post_thumbnail( 'custom-image-size-2' );
the_post_thumbnail( 'custom-image-size-3' );
endwhile; endif; 

Also Read: Custom social media validations with validator jQuery
Also Read: Get posts by meta key and meta value in WordPress

Please let me know what your thoughts or comments are on this article. If you have any suggestion or found any mistake in this article then please let us know.

Latest Comments

Add your comment

Close