Title: Thumbnail Shortcode
Last modified: August 21, 2016

---

# Thumbnail Shortcode

 *  Resolved [wippy](https://wordpress.org/support/users/wippy/)
 * (@wippy)
 * [13 years ago](https://wordpress.org/support/topic/thumbnail-shortcode/)
 * Thumbnail jumps out its div id:
    <div id=”post_thumbnail”>Image should display
   here.</div> but, it displays like this: Image is here.<div id=”post_thumbnail”
   >There is nothing.</div>
 * This is function:
 *     ```
       function post_thumbnail( $atts, $content = null ) {
       	return '<div id="post_thumbnail">' . the_post_thumbnail('thumbnail') . '</div>';
       }
   
       add_shortcode("post_thumbnail", "post_thumbnail");
       ```
   
 * Usage:
 *     ```
       [post_thumbnail]
       ```
   
 * How to fix this?

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [david wolfpaw](https://wordpress.org/support/users/davidjlaietta/)
 * (@davidjlaietta)
 * [13 years ago](https://wordpress.org/support/topic/thumbnail-shortcode/#post-3791982)
 * Hi Wippy,
 * I’d suggest rewriting the function to make each thing that you’re returning a
   discreet element to avoid this.
 *     ```
       function post_thumbnail( $atts, $content = null ) {
            $output = '<div id="post_thumbnail">';
            $output .= the_post_thumbnail('thumbnail');
            $output .= '</div>';
   
            return $output;
       }
   
       add_shortcode("post_thumbnail", "post_thumbnail");
       ```
   
 * This should put the thumbnail back within your div.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years ago](https://wordpress.org/support/topic/thumbnail-shortcode/#post-3791991)
 * the problem is the usage of `the_post_thumbnail()` function which echos the thumbnail
   image code;
 * use `get_the_post_thumbnail()` instead; (you might need to add the post id ?)
 * [http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail](http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail)
 * possibly also have a look at my related post:
    [http://www.transformationpowertools.com/wordpress/insert-featured-image-into-post-content-shortcode](http://www.transformationpowertools.com/wordpress/insert-featured-image-into-post-content-shortcode)
   code [http://pastebin.com/6cQHzRjz](http://pastebin.com/6cQHzRjz)
 *  [frizax](https://wordpress.org/support/users/frizax/)
 * (@frizax)
 * [13 years ago](https://wordpress.org/support/topic/thumbnail-shortcode/#post-3791995)
 * This happened because you are using the_post_thumbnail() which show the thumbnail
   image. For return statement you have to use get_the_post_thumbnail() instead 
   of the_post_thumbnail();
 *     ```
       function post_thumbnail( $atts, $content = null ) {
       	return '<div id="post_thumbnail">' . get_the_post_thumbnail('thumbnail') . '</div>';
       }
   
       add_shortcode("post_thumbnail", "post_thumbnail");
       ```
   
 *  [david wolfpaw](https://wordpress.org/support/users/davidjlaietta/)
 * (@davidjlaietta)
 * [13 years ago](https://wordpress.org/support/topic/thumbnail-shortcode/#post-3791996)
 * Good catch, I didn’t even notice the incorrect usage of the_post_thumbnail.
 * My recommendation can still stand if it is still loading out of the div, as you’re
   being more specific in where you want the code to go.
 *  Thread Starter [wippy](https://wordpress.org/support/users/wippy/)
 * (@wippy)
 * [13 years ago](https://wordpress.org/support/topic/thumbnail-shortcode/#post-3792002)
 * Hi, David Laietta.
    Your function behave the same way like mine. Thank you, anyway.
 * Hi, alchymyth.
    Your solution worked. Thank you.
 * Function:
 *     ```
       function post_thumbnail( $atts, $content = null ) {
       	return '<div id="post_thumbnail">' . get_the_post_thumbnail($post_id, 'thumbnail') . '</div>';
       }
   
       add_shortcode("post_thumbnail", "post_thumbnail");
       ```
   
 *  Thread Starter [wippy](https://wordpress.org/support/users/wippy/)
 * (@wippy)
 * [13 years ago](https://wordpress.org/support/topic/thumbnail-shortcode/#post-3792003)
 * Hi, frizax.
 * You are fast. 😀
 * Well, your code just needs $post_id inside, I don’t know why, but without it 
   inside, image will always show full size.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Thumbnail Shortcode’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 4 participants
 * Last reply from: [wippy](https://wordpress.org/support/users/wippy/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/thumbnail-shortcode/#post-3792003)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
