Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Add thumbnail images to your WordPress posts
Plugin Name: Post Thumbnails
Plugin URI:
Description: Add thumbnail images to posts.
Author: Benedict Eastaugh
Version: 1.0
Author URI:
function add_thumbnail_to_post($the_content) {
if (is_page() || is_single()) return $the_content;
// Just add a custom field to your posts with the name 'thumbnail' and set
// the value to the URI of the image you want to use.
$thumbnail = get_post_meta(get_the_ID(), 'thumbnail', true);
$image = '';
if ($thumbnail) {
$link = get_permalink(get_the_ID());
$image = sprintf('<a class="%s" href="%s"><img alt="%s" src="%s" /></a>',
'post-thumbnail imagelink',
return $image . $the_content;
add_filter('the_content', 'add_thumbnail_to_post');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment