Created
April 21, 2009 13:36
-
-
Save beastaugh/99143 to your computer and use it in GitHub Desktop.
Add thumbnail images to your WordPress posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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