Adding Wordpress Post Thumbnail Image

Single post thumbnail image in wordpress

For adding WordPress Post Thumbnail Image to every post, you need to first edit the wordpress theme functions.php file and add this below code:

add_action( 'after_setup_theme', 'bn_theme_support' );

function bn_theme_support() {
add_theme_support( 'post-thumbnails' ); // This line of code will add featured image option in post writting area.
add_image_size( 'post-thumb', 150, 150, true ); // This line of code is image size in width and height.
}

Now open index.php file or other related files that contain the main content and add this below code to display WordPress Post Thumbnail Image somewhere in those file:

<?php if ( has_post_thumbnail() ) : the_post_thumbnail('post-thumb'); endif; // This line of code will display Thumbnail Image ?>

Published by

Emdad Khan

I am Emdad Khan, A WordPress Theme Developer and Author of BN Web Design Website. A full time Freelancer on WordPress Theme Development & Optimization as well as blogger.

Leave a Reply