{"id":3332,"date":"2014-07-01T14:08:04","date_gmt":"2014-07-01T14:08:04","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/2014\/07\/01\/get-the-post-thumbnail-wordpress-function\/"},"modified":"2021-05-27T15:40:55","modified_gmt":"2021-05-27T19:40:55","slug":"get-the-post-thumbnail-wordpress-function","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/","title":{"rendered":"The get_the_post_thumbnail() WordPress function"},"content":{"rendered":"<p>The <em>get_the_post_thumbnail()<\/em> WordPress function will allow you to get the featured image and display it using your theme or plugin. In this article, we will teach you how to use the <em>get_the_post_thumbnail()<\/em> function to display featured images anywhere you want to.<\/p>\n<p>If you would like more information on creating WordPress plugins, see our tutorial series on <a href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/plugins\/create-a-wordpress-plugin\/\">creating your first WordPress plugin<\/a>.<\/p>\n<div class=\"alert alert-warning\">\n<p><strong>Note:<\/strong> To use the <em>get_the_post_thumbnail() function, you will need to enable support for it within your theme.<\/em><\/p>\n<p>To enable support for the <em>get_the_post_thumbnail()<\/em> function, include the following in your theme&#8217;s <em>functions.php<\/em> file:<\/p>\n<p class=\"code_block\">add_theme_support( &#8216;post-thumbnails&#8217; );<\/p>\n<\/div>\n<h2>Basic usage<\/h2>\n<p class=\"code_block\">&lt;?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?&gt;<\/p>\n<p>In the above code, we are simply displaying the featured image of a post based on the parameters we have defined. Below, you will see the various parameters that can be defined within the <em>get_the_post_thumbnail()<\/em> function.<\/p>\n<h3>Parameters<\/h3>\n<p><strong>$post_id<\/strong>: This is an optional parameter in which you can define the post ID of the post that you will be obtaining the featured image from. If this is not defined, it will display the featured image from the current post that you are viewing.<\/p>\n<p><strong>$size<\/strong>: This is an optional parameter that can be used to determine the size that the featured image is displayed. You may define either a string or an array with the dimensions.<\/p>\n<p><strong>Pre-defined sizes<\/strong>:<\/p>\n<ul class=\"article_list\">\n<li>thumbnail<\/li>\n<li>medium<\/li>\n<li>large<\/li>\n<li>full<\/li>\n<\/ul>\n<p><strong>Custom sizes<\/strong>:<\/p>\n<p>To define a custom size, simply define it within an array, for example:<\/p>\n<p class=\"code_block\">get_the_post_thumbnail($post_id, array(100,100), $attr );<\/p>\n<p>As you can see from the above code, the image size is 100&#215;100.<\/p>\n<p><strong>$attr<\/strong>: This is an optional parameter in which you may use an array to define additional attributes such as the class, alt text, title, etc. This would look something like the following:<\/p>\n<p class=\"code_block\">$attr = array(<br \/>\n&#8216;src&#8217; =&gt; $src,<br \/>\n&#8216;class&#8217; =&gt; &#8220;attachment-$size&#8221;,<br \/>\n&#8216;alt&#8217; =&gt; trim(strip_tags( $attachment-&gt;post_excerpt )),<br \/>\n&#8216;title&#8217; =&gt; trim(strip_tags( $attachment-&gt;post_title )),<br \/>\n);<\/p>\n<p>In the above example, we are storing the array containing the image location, class, alt text, and title within a variable which is later called within the <em>get_the_post_thumbnail()<\/em> function.<\/p>\n<h2>References<\/h2>\n<p>For more information on the <em>get_the_post_thumbnail()<\/em> function, take a look at the <a href=\"https:\/\/codex.wordpress.org\/Function_Reference\/get_the_post_thumbnail\"><em>get_the_post_thumbnail()<\/em> WordPress codex page<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The get_the_post_thumbnail() WordPress function will allow you to get the featured image and display it using your theme or plugin. In this article, we will teach you how to use the get_the_post_thumbnail() function to display featured images anywhere you want to. If you would like more information on creating WordPress plugins, see our tutorial series<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/\"> Read More ><\/a><\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4325,56],"tags":[],"class_list":["post-3332","post","type-post","status-publish","format-standard","hentry","category-wordpress-hosting","category-wordpress"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Learn how to use the Get_the_Post_Thumbnail function in WordPress<\/title>\n<meta name=\"description\" content=\"In this article, we will be showing you the get_the_post_thumbnail() WordPress function that can be used to show featured images within your WordPress plugins or themes.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn how to use the Get_the_Post_Thumbnail function in WordPress\" \/>\n<meta property=\"og:description\" content=\"In this article, we will be showing you the get_the_post_thumbnail() WordPress function that can be used to show featured images within your WordPress plugins or themes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2014-07-01T14:08:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-27T19:40:55+00:00\" \/>\n<meta name=\"author\" content=\"Jeff Matson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeff Matson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/\"},\"author\":{\"name\":\"Jeff Matson\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/83776252b196c020e4352a3796e5642b\"},\"headline\":\"The get_the_post_thumbnail() WordPress function\",\"datePublished\":\"2014-07-01T14:08:04+00:00\",\"dateModified\":\"2021-05-27T19:40:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/\"},\"wordCount\":406,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"articleSection\":[\"WordPress Hosting\",\"WordPress Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/\",\"name\":\"Learn how to use the Get_the_Post_Thumbnail function in WordPress\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2014-07-01T14:08:04+00:00\",\"dateModified\":\"2021-05-27T19:40:55+00:00\",\"description\":\"In this article, we will be showing you the get_the_post_thumbnail() WordPress function that can be used to show featured images within your WordPress plugins or themes.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The get_the_post_thumbnail() WordPress function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/83776252b196c020e4352a3796e5642b\",\"name\":\"Jeff Matson\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/jeffma\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn how to use the Get_the_Post_Thumbnail function in WordPress","description":"In this article, we will be showing you the get_the_post_thumbnail() WordPress function that can be used to show featured images within your WordPress plugins or themes.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/","og_locale":"en_US","og_type":"article","og_title":"Learn how to use the Get_the_Post_Thumbnail function in WordPress","og_description":"In this article, we will be showing you the get_the_post_thumbnail() WordPress function that can be used to show featured images within your WordPress plugins or themes.","og_url":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2014-07-01T14:08:04+00:00","article_modified_time":"2021-05-27T19:40:55+00:00","author":"Jeff Matson","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Jeff Matson","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/"},"author":{"name":"Jeff Matson","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/83776252b196c020e4352a3796e5642b"},"headline":"The get_the_post_thumbnail() WordPress function","datePublished":"2014-07-01T14:08:04+00:00","dateModified":"2021-05-27T19:40:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/"},"wordCount":406,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"articleSection":["WordPress Hosting","WordPress Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/","url":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/","name":"Learn how to use the Get_the_Post_Thumbnail function in WordPress","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2014-07-01T14:08:04+00:00","dateModified":"2021-05-27T19:40:55+00:00","description":"In this article, we will be showing you the get_the_post_thumbnail() WordPress function that can be used to show featured images within your WordPress plugins or themes.","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/get-the-post-thumbnail-wordpress-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"The get_the_post_thumbnail() WordPress function"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/83776252b196c020e4352a3796e5642b","name":"Jeff Matson","url":"https:\/\/www.inmotionhosting.com\/support\/author\/jeffma\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":null,"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=3332"}],"version-history":[{"count":2,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3332\/revisions"}],"predecessor-version":[{"id":73281,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3332\/revisions\/73281"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=3332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=3332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=3332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}