If I use:
add_image_size('main_image', 750, 375, true);
to add additional thumbnail size. Then how can i get that size if i have only key main_image
.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityIf I use:
add_image_size('main_image', 750, 375, true);
to add additional thumbnail size. Then how can i get that size if i have only key main_image
.
This is answered here: Get post thumbnail size
global $_wp_additional_image_sizes;
// Output width
echo $_wp_additional_image_sizes['main_image']['width'];
// Output height
echo $_wp_additional_image_sizes['main_image']['height'];
To use the new image size in a theme you need to call to it with
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'main_image' ); } ?>
If you need additional sizes just add more.
add_image_size('main_image', 750, 375, true);
add_image_size('main_image_2', 650, 275, true);
add_image_size('main_image_3', 550, 175, true);
You can learn how this function works here http://codex.wordpress.org/Function_Reference/add_image_size
Use the_post_thumbnail()
to output the featured image at the specified size:
<?php the_post_thumbnail( 'main_image' ); ?>
Use get_the_post_thumbnail()
to return the HTML image markup for the image at the specified size:
<?php get_the_post_thumbnail( get_the_ID(), 'main_image' ); ?>