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_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; 

Hi, I'm Saurav, the developer behind usingphp. Donate to help me keep usingphp free and maintained.

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