How To Add Post and Page Thumbnail (Featured Images) Support

Snippets by IsItWP

Are you looking for a way to add post and page thumbnail (featured images) support to a theme? This snippet will let you add featured images to posts and pages.


  1. Add this code to your theme’s functions.php file or in a site-specific plugin:
    add_theme_support( 'post-thumbnails' );

    If you want to add featured images to pages or posts only, add one of the following snippets instead:

    • This snippet adds support for pages only:
      // This adds support for pages only:
      add_theme_support( 'post-thumbnails', array( 'page' ) );
    • This snippet adds support for posts only:
      // And this adds support for posts only:
      add_theme_support( 'post-thumbnails', array( 'post' ) );
  2. Then, add this snippet inside The Loop.

    // To get the thumbnail in your post, you add the following inside the loop:
    if ( has_post_thumbnail() ) {
    	set_post_thumbnail_size( 400, 150 ); # width, height #

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 19 Best WordPress Plugins for Photographers.

Comments   Leave a Reply

  1. But what is the Loop though

    1. For more details about the Loop, check out: https://www.isitwp.com/the-ultimate-guide-to-the-wordpress-loop/

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!