I am trying to set the width of a post thumbnail using:
the_post_thumbnail()
The width of the image needs to be 210px
but the height is not meant to be fixed as all the images will be different sizes. I have tried:
the_post_thumbnail( array( 210, 0 ) )
But this does not work. Any ideas?
Thanks.
To set your Featured Image, scroll down in your page or post underneath the Publish button. There you'll see a link that says Set featured image. Clicking it will bring you to your media library where you can either upload something new or choose an image you already have on your website.
Add this inside your functions.php
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'category-thumb', 210, 9999 ); //210 pixels wide (and unlimited height)
}
Use it inside your theme's template files
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'category-thumb' ); } ?>
For default thumbnail add this inside your functions.php
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 9999 ); // default Post Thumbnail dimensions
}
Reference: Here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With