adsense

How to Set Thumbnails in WordPress





Set a Featured Image
1. Log into WordPress and click 'Posts' in the left menu. Hover over the post that you would like to have a thumbnail, and click the 'Edit' link that appears. Look for a 'Set Featured Image' link in the lower-right corner. If it does not exist, your theme is not yet compatible with thumbnails and needs editing.
2. Click the 'Set Featured Image' link on the post editing screen's lower-right corner. Follow the prompts to upload an image, but do not click the 'Insert' button. Instead, click 'Set as Featured Image' next to the button.

3. Click the 'X' at the top-right corner of the media uploader to make it disappear. Check that your image appears in the 'Featured Image' box. Click the blue 'Update' button to save the post with the thumbnail.
Add Theme Support for Thumbnails
4. Open the functions.php file of your current WordPress theme in the plain text or code editor of your choosing. This file is found here:/yoursite/wp-content/themes/name-of-theme/Add this code anywhere between the
tags of the file, preferably at the very bottom or very top:if (function_exists('add_theme_support')) {add_theme_support('post-thumbnails');}
5. Start a new line and add in the following code:set_post_thumbnails_size(50, 50, true);Between the parentheses are three parameters for this function: width, height and cropping mode. Set the width to whatever you want, and set the height to 9999 if you want variable height. WordPress takes thumbnails and sizes them to the width first and the height second, and with variable height it leaves the height alone. Include the 'true' parameter to tell WordPress to hard-crop the thumbnail to exact dimensions. WordPress crops from the center of images.
6. Add various thumbnail sizes by including the following function on the next line:add_image_size('size-name', 300, 200);Here, the 'size-name' is whatever you want to call that image size when you use it in theme templates, so give it a name that makes sense and is easy to remember. The next two parameters are height and width, just like in the set_post_thumbnails_size() function.
Add Thumbnails to Template Files
7. Open up your template files in your theme's folder. Wherever you want thumbnails to appear, add this code:
Use
instead to use a different thumbnail size set in the functions.php file.
8. Wrap the thumbnail function in conditional tags to keep WordPress from trying to load thumbnails when posts do not have them. Your code should look like this:



9. Use an Else statement to show a fallback image for posts without thumbnails. Fallbacks are useful for site designs that would look awkward without some type of image in the thumbnail spot. Here is an example:



/your-fallback.png' />

Comments

0 Responses to "How to Set Thumbnails in WordPress"

Post a Comment

Popular Posts

About