BlogThemes

How to Get the Post Thumbnail URL in WordPress

There are at all times a bunch of our readers who’re making an attempt to graduate the newbie degree early and step into WordPress improvement. Lots of them begin by hacking their WordPress themes, creating little one themes, or writing plugins. This makes them come throughout puzzling challenges. One such reader just lately requested us how you can get the submit thumbnail URL in WordPress. The aim right here is to simply get the post thumbnail URL after which use it with their very own markup. On this article, we are going to present you how you can get the submit thumbnail URL in WordPress.

Notice: It’s essential to know the fundamentals of how WordPress themes work.

Merely paste this code contained in the loop code that you’re writing.

1
2
3
4
5
<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
echo $thumb_url[0];
?>

Be certain that to interchange thumbnail-size to no matter picture measurement you wish to get. Default sizes are thumbnail, medium, massive, and full. You can even use add and use additional image sizes. If you’re utilizing a customized picture measurement then ensure to regenerate thumbnails. You can even set a default fallback picture for submit thumbnails.

What this code does is that we first get the submit thumbnail ID. Then we use that id to get the picture path or URL utilizing wp_get_attachment_image_srcperform, which returns an array that you need to use with your individual code.

Download The WPSaviour App Now

Related posts
Beginner’s GuideBest WordPress PluginsBlog

9 Best Social Proof Plugins for WordPress & WooCommerce (2020)

Tips

Simplify Your Online Presence With WordPress: Themes, Plugins, Products and Services

Tips

How To Disable The WordPress User Admin Toolbar

Tips

Buying WordPress Themes The Smart Way

Leave a Reply

Your email address will not be published.

Pay in your preferred currency
Indian rupee
Euro