Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Add thumbnail images to your WordPress posts
<?php
/*
Plugin Name: Post Thumbnails
Plugin URI: http://tarskitheme.com/
Description: Add thumbnail images to posts.
Author: Benedict Eastaugh
Version: 1.0
Author URI: http://extralogical.net/
*/
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',
$link,
'',
$thumbnail);
}
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
Something went wrong with that request. Please try again.