Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am in the process of developing a new theme for my blog and am making a featured content slider. The issue that I am having is getting wordpress to force the image to the dimensions that I want it to be. The exact dimensions are 494px x 168px. I've tried simple using the_post_thumbnail( array(494, 168) );, but that didn't work. I also tried adding a custom image size to my functions file. This would sometimes get the height right (but not always), but didn't get the width right a single time. Could somebody please give me a way to force the dang image to be 494px X 168px?

share|improve this question

1 Answer 1

up vote 9 down vote accepted

For post thumbnails you can either crop and image to the thumbnail size or scale the image. To enable crop you can call the thumbnail 1 of 2 ways.

  1. Name a size in the functions.php file like so:

    <?php add_image_size( 'my-post-thumbnail', 494, 168, true ); ?>
    

and then call it in the theme file

    <?php the_post_thumbnail('my-post-thumbnail'); ?>

The true tells wordpress to crop the image rather than scale, to scale leave true out.

  1. Call the size just in the theme file

    <?php the_post_thumbnail(494, 168, true); ?>
    

Also, the_post_thumbnail doesn't work on images already uploaded. To test if the sizes truly aren't working upload a new file after adding the new thumbnail size/calling it in your theme file.

Mark on Wordpress has a good tutorial on Post Thumbnails http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/

share|improve this answer
    
Thanks! I got it working now :) –  Adam Thompson Nov 27 '10 at 22:44
    
you can also check out the regenerate thumbnails plugin (wordpress.org/extend/plugins/regenerate-thumbnails) if you really need to resize the images you currently have uploaded. –  Cronco Jan 23 '11 at 3:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.