Title: get_the_post_thumbnail
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_the_post_thumbnail( int|WP_Post|null $post = null, string|int[] $size, string|array $attr ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#wp--skip-link--target)

Retrieves the post thumbnail.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#description)󠁿

When a theme adds ‘post-thumbnail’ support, a special ‘post-thumbnail’ image size
is registered, which differs from the ‘thumbnail’ image size managed via the Settings
> Media screen.

When using [the_post_thumbnail()](https://developer.wordpress.org/reference/functions/the_post_thumbnail/)
or related functions, the ‘post-thumbnail’ image size is used by default, though
a different size can be specified instead as needed.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#parameters)󠁿

 `$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
|nulloptional

Post ID or [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
object. Default is global `$post`.

Default:`null`

`$size`string|int[]optional

Image size. Accepts any registered image size name, or an array of width and height
values in pixels (in that order). Default `'post-thumbnail'`.

`$attr`string|arrayoptional

Query string or array of attributes. Default empty.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#return)󠁿

 string The post thumbnail image tag.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#more-information)󠁿

If the required `add_theme_support( 'post-thumbnails' );` in the current theme’s
functions.php file is attached to a hook, it must be must be called before the [`init`](https://developer.wordpress.org/reference/hooks/init/)
hook is fired. The _init_ hook may be too late for some features. If attached to
a hook, it must be [`after_setup_theme`](https://developer.wordpress.org/reference/hooks/after_setup_theme/).

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#source)󠁿

    ```php
    function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = '' ) {
    	$post = get_post( $post );

    	if ( ! $post ) {
    		return '';
    	}

    	$post_thumbnail_id = get_post_thumbnail_id( $post );

    	/**
    	 * Filters the post thumbnail size.
    	 *
    	 * @since 2.9.0
    	 * @since 4.9.0 Added the `$post_id` parameter.
    	 *
    	 * @param string|int[] $size    Requested image size. Can be any registered image size name, or
    	 *                              an array of width and height values in pixels (in that order).
    	 * @param int          $post_id The post ID.
    	 */
    	$size = apply_filters( 'post_thumbnail_size', $size, $post->ID );

    	if ( $post_thumbnail_id ) {

    		/**
    		 * Fires before fetching the post thumbnail HTML.
    		 *
    		 * Provides "just in time" filtering of all filters in wp_get_attachment_image().
    		 *
    		 * @since 2.9.0
    		 *
    		 * @param int          $post_id           The post ID.
    		 * @param int          $post_thumbnail_id The post thumbnail ID.
    		 * @param string|int[] $size              Requested image size. Can be any registered image size name, or
    		 *                                        an array of width and height values in pixels (in that order).
    		 */
    		do_action( 'begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size );

    		if ( in_the_loop() ) {
    			update_post_thumbnail_cache();
    		}

    		$html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );

    		/**
    		 * Fires after fetching the post thumbnail HTML.
    		 *
    		 * @since 2.9.0
    		 *
    		 * @param int          $post_id           The post ID.
    		 * @param int          $post_thumbnail_id The post thumbnail ID.
    		 * @param string|int[] $size              Requested image size. Can be any registered image size name, or
    		 *                                        an array of width and height values in pixels (in that order).
    		 */
    		do_action( 'end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size );

    	} else {
    		$html = '';
    	}

    	/**
    	 * Filters the post thumbnail HTML.
    	 *
    	 * @since 2.9.0
    	 *
    	 * @param string       $html              The post thumbnail HTML.
    	 * @param int          $post_id           The post ID.
    	 * @param int          $post_thumbnail_id The post thumbnail ID, or 0 if there isn't one.
    	 * @param string|int[] $size              Requested image size. Can be any registered image size name, or
    	 *                                        an array of width and height values in pixels (in that order).
    	 * @param string|array $attr              Query string or array of attributes.
    	 */
    	return apply_filters( 'post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post-thumbnail-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/post-thumbnail-template.php#L165)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/post-thumbnail-template.php#L165-L237)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#hooks)󠁿

 [do_action( ‘begin_fetch_post_thumbnail_html’, int $post_id, int $post_thumbnail_id, string|int[] $size )](https://developer.wordpress.org/reference/hooks/begin_fetch_post_thumbnail_html/)

Fires before fetching the post thumbnail HTML.

 [do_action( ‘end_fetch_post_thumbnail_html’, int $post_id, int $post_thumbnail_id, string|int[] $size )](https://developer.wordpress.org/reference/hooks/end_fetch_post_thumbnail_html/)

Fires after fetching the post thumbnail HTML.

 [apply_filters( ‘post_thumbnail_html’, string $html, int $post_id, int $post_thumbnail_id, string|int[] $size, string|array $attr )](https://developer.wordpress.org/reference/hooks/post_thumbnail_html/)

Filters the post thumbnail HTML.

 [apply_filters( ‘post_thumbnail_size’, string|int[] $size, int $post_id )](https://developer.wordpress.org/reference/hooks/post_thumbnail_size/)

Filters the post thumbnail size.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#related)󠁿

| Uses | Description | 
| [in_the_loop()](https://developer.wordpress.org/reference/functions/in_the_loop/)`wp-includes/query.php` |

Determines whether the caller is in the Loop.

  | 
| [get_post_thumbnail_id()](https://developer.wordpress.org/reference/functions/get_post_thumbnail_id/)`wp-includes/post-thumbnail-template.php` |

Retrieves the post thumbnail ID.

  | 
| [update_post_thumbnail_cache()](https://developer.wordpress.org/reference/functions/update_post_thumbnail_cache/)`wp-includes/post-thumbnail-template.php` |

Updates cache for thumbnails in the current loop.

  | 
| [wp_get_attachment_image()](https://developer.wordpress.org/reference/functions/wp_get_attachment_image/)`wp-includes/media.php` |

Gets an HTML img element representing an image attachment.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  |

[Show 3 more](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#)

| Used by | Description | 
| [the_post_thumbnail()](https://developer.wordpress.org/reference/functions/the_post_thumbnail/)`wp-includes/post-thumbnail-template.php` |

Displays the post thumbnail.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | `$post` can be a post ID or [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/) object. | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 13 content](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#comment-content-314)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-314)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-314)
     Vote results for this note: 15[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-314)
 4.  **Styling Post Thumbnails**
      Post Thumbnails are given a class “wp-post-image”.
     They also get a class depending on the size of the thumbnail being displayed. 
     You can style the output with these CSS selectors:
 5.      ```line-numbers
         img.wp-post-image
         	img.attachment-thumbnail
         	img.attachment-medium
         	img.attachment-large
         	img.attachment-full
         ```
     
 6.  You can also give Post Thumbnails their own class:
 7.      ```php
         // Give the Post Thumbnail a class "alignleft".
         echo get_the_post_thumbnail( $post_id, 'thumbnail', array( 'class' => 'alignleft' ) );
         ```
     
 8.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%3Freplytocom%3D314%23feedback-editor-314)
 9.   [Skip to note 14 content](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#comment-content-311)
 10.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-311)
 11. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-311)
     Vote results for this note: 8[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-311)
 12. **Thumbnail Sizes**
      The default image sizes of WordPress are “thumbnail”, “medium”,“
     large” and “full” (the size of the image you uploaded). These image sizes can 
     be configured in the WordPress Administration Media panel under Settings > Media.
     Themes may also add “post-thumbnail”. This is how you can use these default sizes
     with `get_the_post_thumbnail()`:
 13.     ```php
         // without parameter -> Post Thumbnail (as set by theme using set_post_thumbnail_size())
         get_the_post_thumbnail( $post_id );                   
     
         get_the_post_thumbnail( $post_id, 'thumbnail' );      // Thumbnail (Note: different to Post Thumbnail)
         get_the_post_thumbnail( $post_id, 'medium' );         // Medium resolution
         get_the_post_thumbnail( $post_id, 'large' );          // Large resolution
         get_the_post_thumbnail( $post_id, 'full' );           // Original resolution
     
         get_the_post_thumbnail( $post_id, array( 100, 100) ); // Other resolutions
         ```
     
 14. Register new image sizes for Post Thumbnails with: `add_image_size()`.
      To set
     the default size for Post Thumbnails see: `set_post_thumbnail_size()`.
 15.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%3Freplytocom%3D311%23feedback-editor-311)
 16.  [Skip to note 15 content](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#comment-content-310)
 17.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-310)
 18. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-310)
     Vote results for this note: 6[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-310)
 19. **Sample Usage**
 20.     ```php
         <?php $pages = get_pages( array( 'child_of' => 1 ) ); ?> 
         <ul>
         	<?php foreach ( $pages as $page ) : ?>
         		<li>
         			<?php echo get_the_post_thumbnail( $page->ID, 'thumbnail' ); ?>
         			<h1><?php echo apply_filters( 'the_title', $page->post_title, $page->ID ); ?></h1>
         			<?php echo apply_filters( 'the_content', $page->post_content ); ?>
         		</li>
         	<?php endforeach; ?>
         </ul>
         ```
     
 21.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%3Freplytocom%3D310%23feedback-editor-310)
 22.  [Skip to note 16 content](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#comment-content-312)
 23.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-312)
 24. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-312)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-312)
 25. **Post Thumbnail Linking to the Post Permalink**
 26. This example shows the 5 latest Post Thumbnails linked to their Post permalink.
 27.     ```php
         $posts = get_posts( array( 'posts_per_page' => 5 ) );
         foreach ( $posts as $_post ) {
         	if ( has_post_thumbnail( $_post->ID ) ) {
         		echo '<a href="' . get_permalink( $_post->ID ) . '" title="' . esc_attr( $_post->post_title ) . '">';
         		echo get_the_post_thumbnail( $_post->ID, 'thumbnail' );
         		echo '</a>';
         	}
         }
         ```
     
 28.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%3Freplytocom%3D312%23feedback-editor-312)
 29.  [Skip to note 17 content](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#comment-content-1741)
 30.   [Shaikh Muhammad Arif Uddin](https://profiles.wordpress.org/smarif/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-1741)
 31. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-1741)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-1741)
 32. **Remove width and height attributes from the returning html**
 33. `get_the_post_thumbnail` function produces html with `img` tag which includes 
     width, height, src, class, alt and title attributes. The following code snippet
     is useful if someone wish to remove width and height attribute.
 34. This function provides `'post_thumbnail_html'` filter before returning the html.
 35.     ```php
         add_filter( 'post_thumbnail_html', 'remove_thumbnail_width_height', 10, 5 );
     
         function remove_thumbnail_width_height( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
             $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
             return $html;
         }
         ```
     
 36.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%3Freplytocom%3D1741%23feedback-editor-1741)
 37.  [Skip to note 18 content](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#comment-content-2813)
 38.   [jesperstender](https://profiles.wordpress.org/jesperstender/)  [  8 years ago  ](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-2813)
 39. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-2813)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-2813)
 40. You can set more than just classes –
      If you want to optimize your SrcSet values
     you can do something like this
 41.     ```php
          echo get_the_post_thumbnail($post->ID, 'WhateverSize-Large', array('title' => 'WhateverTitle', 'sizes' => '(max-width: 320px) 288px, (max-width: 375px) 343px, (max-width: 425px) 393px, (max-width: 540px) 493px, (max-width: 768px) 320px, (max-width: 999px) 435px, 288px')); 
         ```
     
 42. etc.
 43. Normally in a grid, the srcset can go 100vw – which is sometimes way too big –
     
     this method lets you control that.
 44.  * Great trick! I would otherwise have to use the `wp_calculate_image_sizes` filter–
        which doesn’t support attributes/extra hints yet (though planned to be released
        for the near future).
      * [strarsis](https://profiles.wordpress.org/strarsis/) [5 years ago](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-5339)
 45.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%3Freplytocom%3D2813%23feedback-editor-2813)
 46.  [Skip to note 19 content](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#comment-content-313)
 47.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-313)
 48. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-313)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-313)
 49. **Post Thumbnail Linking to large Image Size**
      This example links to the “large”
     Post Thumbnail image size and must be used within The Loop.
 50.     ```php
         if ( has_post_thumbnail() ) {
         	$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
         	if ( ! empty( $large_image_url[0] ) ) {
         		echo '<a href="' . esc_url( $large_image_url[0] ) . '" title="' . the_title_attribute( array( 'echo' => 0 ) ) . '">';
         		echo get_the_post_thumbnail( $post->ID, 'thumbnail' ); 
         		echo '</a>';
         	}
         }
         ```
     
 51.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%3Freplytocom%3D313%23feedback-editor-313)
 52.  [Skip to note 20 content](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#comment-content-1982)
 53.   [Anthony Hortin](https://profiles.wordpress.org/ahortin/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-1982)
 54. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-1982)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-1982)
 55. See Also:
      [the_post_thumbnail()](https://developer.wordpress.org/reference/functions/the_post_thumbnail/)
 56.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%3Freplytocom%3D1982%23feedback-editor-1982)
 57.  [Skip to note 21 content](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#comment-content-6826)
 58.   [John Dorner](https://profiles.wordpress.org/jdorner/)  [  2 years ago  ](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-6826)
 59. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-6826)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-6826)
 60. When specifying a size e.g. `get_the_post_thumbnail(null, [300, 300])`, the image’s
     proportions are preserved and the width/height are maximum sizes. If the a dimension’s
     are smaller than specified, then the image returned will be the full size image.
 61. Example 1: Your image is 500px (width) by 1000px (height), the image returned 
     will be 150px by 300px.
 62. Example 2: Your image is 100px by 100px the the image size returned will be 100px
     by 100px
 63.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%3Freplytocom%3D6826%23feedback-editor-6826)
 64.  [Skip to note 22 content](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#comment-content-2189)
 65.   [joshcanhelp](https://profiles.wordpress.org/joshcanhelp/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-2189)
 66. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-2189)
     Vote results for this note: -2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-2189)
 67. Post thumbnails in a listing context are often linked to the content they’re representing.
     Instead of adding that every time, here is a filter you can add that will do it
     automatically based on an `$attr` passed in.
 68.     ```php
         /**
          * Link thumbnails to their posts based on attr
          *
          * @param $html
          * @param int $pid
          * @param int $post_thumbnail_id
          * @param int $size
          * @param array $attr
          *
          * @return string
          */
     
         function wpdev_filter_post_thumbnail_html( $html, $pid, $post_thumbnail_id, $size, $attr ) {
     
         	 if ( ! empty( $attr[ 'link_thumbnail' ] ) ) {
     
         		$html = sprintf(
         			'<a href="%s" title="%s" rel="nofollow">%s</a>',
         			get_permalink( $pid ),
         			esc_attr( get_the_title( $pid ) ),
         			$html
         		);
         	 }
     
         	return $html;
         }
     
         add_filter( 'post_thumbnail_html', 'wpdev_filter_post_thumbnail_html', 10, 5 );
         ```
     
 69. Just “add the above to your functions.php file” (there’s probably a better place
     for it) and use it like this in a template file:
 70.     ```php
          'my-custom-class', // classes
         		'link_thumbnail' => TRUE, // yes please link my thumbnail
         	]
         );
         ?>
         ```
     
 71.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%3Freplytocom%3D2189%23feedback-editor-2189)
 72.  [Skip to note 23 content](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#comment-content-1008)
 73.   [axxomano](https://profiles.wordpress.org/axxomano/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-1008)
 74. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-1008)
     Vote results for this note: -15[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-1008)
 75. To give class to the featured image post thumbnail
 76.     ```php
         // Give the Post_Thumbnail a class "alignleft".
         echo get_the_post_thumbnail( $post_id, 'post_thumbnail', array( 'class' => 'alignleft' ) );
         ```
     
 77.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%3Freplytocom%3D1008%23feedback-editor-1008)
 78.  [Skip to note 24 content](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/?output_format=md#comment-content-1013)
 79.   [ravimane1991](https://profiles.wordpress.org/ravimane1991/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-1013)
 80. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-1013)
     Vote results for this note: -20[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%23comment-1013)
 81. To get full featured image
 82.     ```php
         the_post_thumbnail( 'large','style=max-width:100%;height:auto;');
         ```
     
 83.  * Thank you very much!
      * [joaodiasjr](https://profiles.wordpress.org/joaodiasjr/) [8 years ago](https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/#comment-2814)
 84.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F%3Freplytocom%3D1013%23feedback-editor-1013)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_post_thumbnail%2F)
before being able to contribute a note or feedback.