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.
Instructions:
- 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' ) );
- This snippet adds support for pages only:
-
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 # the_post_thumbnail(); }
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.
But what is the Loop though
For more details about the Loop, check out: https://www.isitwp.com/the-ultimate-guide-to-the-wordpress-loop/