Shortcode: Post Thumbnails

Add following code where you want to display it.


[post-thumbnail size="thumbnail" link="" alt="Marvellous Image" title="Marvellous title"]
[post-thumbnail width="540" height="250" link="" alt="Marvellous Image" title="Marvellous title"]

Add following snippet to “functions.php”


function post_thumbnail_shortcode($atts){
    global $post;
            'size' => size_value(),
            'width' => null,
            'height' => null,
            'link' => '',
            'alt' => $post->post_excerpt,
            'title' => $post->post_title,
    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>