Post thumbnails are pretty useful and pretty easy to use in WordPress. Simply add:
To a theme’s functions.php file and you’ll get a Featured Image module on the admin screen for posts which allows you to select one.
It is also very easy to output that image as an HTML
But what if you just need the URL? Say, you’re going to use it as a
background-image on an element rather than a content image. Unfortunately there is no super easy/obvious function for that.
Within the loop, you’ll have to do:
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
$thumb_url = $thumb_url_array;
Then $thumb_url will be that URL.
Latest posts by admin (see all)
- Install and Running Supervisord in virtualenv python 2.7 - January 24, 2019
- Urgent fix: Briefly unavailable for scheduled maintenance. Check back in a minute. - January 22, 2019
- Change WordPress post date format to time ago - January 21, 2019
Also published on Medium.