Nistor Alexandru
Nistor Alexandru

Reputation: 5393

Setting thumbnail featured image size not working properly

Hi I just started today on creating my first Wordpress Theme and I am trying to create a featured Image for each post.Aldo I have managed to acomplish that it seems that the sizes I am giving it are not taking effect.Here is my code:

if(function_exists('add_theme_support')){
   add_theme_support('post-thumbnails' , array('post'));
   set_post_thumbnail_size(200,120);
}

if(function_exists('has_post_thumbnail') && has_post_thumbnail()){
      the_post_thumbnail();
}

It seems that my featured images are not always set to the same size.For example if the image is smaller then what size I set it will remain the same , for big images the width is the same but for some the height is different.

What am I doing wrong here?

Upvotes: 0

Views: 913

Answers (1)

scottoliver
scottoliver

Reputation: 536

Are you setting the thumbnail size in functions.php? It will not work properly if it's just in index.php or another theme file.

From the codex:

This feature must be called before the init hook is fired. That means it needs to be placed directly into functions.php or within a function attached to the 'after_setup_theme' hook. For custom post types, you can also add post thumbnails using the register_post_type function as well.

the_post_thumbnail() displays the thumbnail and should be placed where you want the thumbnail to display.

Upvotes: 1

Related Questions