metinsaylan // rogue developer

How to enable post thumbnails for pages

In the new versions of WordPress this would be enabled by default, plus most themes enable it. But if your theme doesn’t have post thumbnail feature for pages, you can easily enable this feature by adding the following code to your functions.php file..


 add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );  

You can also add other post types to the array. This code will enable adding thumbnails only. They will not be visible unless you edit the page template. Open page.php file and add the following code somewhere in the loop to display page thumbnail:

<?php the_post_thumbnail( 'thumbnail' ); ?>  

How to change post thumbnail size

By default thumbnails will use your system thumbnail size. If you want to change thumbnail size for your theme you got to use set_post_thumbnail_size function to set it up:

set_post_thumbnail_size( 165, 90, true ); // width, height, cropmode

Adding custom image size

I prefer adding custom image sizes first:

add_image_size( 'portfolio-thumb', 165, 90, true );

and then we can use this tag to display thumbnail of this size:

<?php the_post_thumbnail( 'portfolio-thumb' ); ?>

Displaying thumbnails in different size

You can also use array of 2, to set thumbnail size:

<?php the_post_thumbnail( array(200,200) ); ?>

WordPress will display closest size that apply if you use array as a size. If it can’t find a match in the cropped thumbnails, it will scale the nearest one. So I don’t prefer this option.

Search How to enable post thumbnails for pages on Google