JadoBulku
JadoBulku

Reputation: 47

How to set Wordpress Featured thumbnail to fixed width and auto height

I want to change post featured thumbnail to 1300px width and auto height since I don't want to crop the images, but nothing I do isn't working. At first the code was like this

add_image_size('discussion_post_feature_image', 1300);

I saw some answers here and tried it like this but didn't work

add_image_size('discussion_post_feature_image', 1300, 9999, false);

Is there any other way so I can upscale the image to that width but to not change the height? Thanks in advance.

Upvotes: 1

Views: 696

Answers (2)

Shital Marakana
Shital Marakana

Reputation: 2887

For this to work, you must have added the thumbnail support. You can use the following code in functions.php to add the support

function wpsm_setup_theme() {
   add_theme_support( 'post-thumbnails' );
   add_image_size( 'discussion_post_feature_image', 1300, 9999, true );
}

add_action( 'after_setup_theme', 'wpsm_setup_theme' );

and to display the image:

if ( has_post_thumbnail() ) {
 the_post_thumbnail("discussion_post_feature_image");
}else{
 echo "No thumbnail";
}

Upvotes: 0

Arshiva
Arshiva

Reputation: 456

If you want to crop the image, instead of passing false, you shouls pass true in like-- add_image_size('discussion_post_feature_image', 1300, 9999, true);

And that should do.

Upvotes: 1

Related Questions