Shortcode: Post Thumbnails

Add following code where you want to display it.

Usage

[post-thumbnail]
[post-thumbnail size="thumbnail" link="http://www.graphicbeacon.com" alt="Marvellous Image" title="Marvellous title"]
[post-thumbnail width="540" height="250" link="http://www.graphicbeacon.com" alt="Marvellous Image" title="Marvellous title"]

Add following snippet to “functions.php”

Snippet

add_shortcode('post-thumbnail','post_thumbnail_shortcode');
function post_thumbnail_shortcode($atts){
 
    global $post;
 
    extract(shotcode_atts(array(
            'size' => size_value(),
            'width' => null,
            'height' => null,
            'link' => '',
            'alt' => $post->post_excerpt,
            'title' => $post->post_title,
    ),$atts));
 
    if ($link != ''){ return "<a title=\"$title\" href=\"".trim($link)."\">"; }
 
    function size_value() {
        if (isset($width) && isset($height)) {
            return array($width,$height);
        } else {
            return $size;
        }
    }
   if ( function_exists('has_post_thumbnail') && has_post_thumbnail() ) {
      the_post_thumbnail($size,array('title' => $title, 'alt' => $alt));
   }
 
    if ($link != ''){ return "</a>"; }
 
}

Courtesy: GraphicBeacon

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>