Please wait, loading...

 

How to add featured Image Support. - Emerald Tech

April 21, 20120

Lets talk about another wordpress trick.

Have you ever opened your post editor and found there is no featured image box in it?

A lot will say “yes”

The reason being that wordpress requires you to add theme support for thumbnails manually through your functions.php or some plug-in.

Adding the support manually is very simple. Open the functions.php file which lies in your active theme’s folder and paste this code.

Adding theme support for all post types.

add_theme_support('post-thumbnails');

Adding support only for pages.

add_theme_support(array('page'));

Adding Thumbnail Sizes

You can add an option so that all thumbnails have an exact size and will be cropped to that size without keeping the aspect ratio of the image by setting a size and setting the third crop parameter to be true, as shown below

set_post_thumbnail_size(150,150,true);

For using the thumbnail in theme, there are three functions.

  • has_post_thumbnail() returns ‘true’ if a thumbnail has been set
  • the_post_thumbnail() echos a string containing the thumbnail < img alt=”” / > tag
  • get_the_post_thumbnail() returns a string containing the thumbnail < img alt=”” /> tag

Read more about thumnail on this link

Yumna Tatheer

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright @ Yamna Tatheer CEO Emerald Technologies Registration Number: 3520166158082