Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set only the image width of a Wordpress thumbnail

Tags:

wordpress

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.

like image 847
badcoder Avatar asked Mar 16 '12 15:03

badcoder


People also ask

How do I change the thumbnail on my WordPress site?

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.


1 Answers

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.

like image 132
The Alpha Avatar answered Oct 19 '22 03:10

The Alpha