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;
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;
Recommanded Articles
- Generate Dummy Posts in WordPress
- How to add captcha in Contact Form 7
- how to create a cron job in wordpress
- How to get form data in Contact Form 7
- Insert Update Delete Select query in WordPress
- How to increase website speed
- Create plugin in WordPress in which create table in DB on activate
- Create new tab under my account WooCommerce frontend
- Custom image sizes in WordPress
- Get posts by meta key and meta value in WordPress
Latest Comments