Skip to content

Instantly share code, notes, and snippets.

@beastaugh
Created April 21, 2009 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beastaugh/99143 to your computer and use it in GitHub Desktop.
Save beastaugh/99143 to your computer and use it in GitHub Desktop.
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