public
Last active

Add thumbnail images to your WordPress posts

  • Download Gist
post_thumbnails.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<?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');
 
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.