Skip to content

Instantly share code, notes, and snippets.

@asbjornu
Last active December 18, 2015 09:19
Show Gist options
  • Save asbjornu/5760192 to your computer and use it in GitHub Desktop.
Save asbjornu/5760192 to your computer and use it in GitHub Desktop.
WordPress' missing the_post_thumbnail_url() function.
<?php
/**
* Outputs the URL of the "Featured Image", also known as "Post Thumbnail".
* @param $post_id (optional) The ID of the Post whose Thumbnail you wish to output. When used within "The Loop", this parameter can be ommitted.
* @return void
*/
function the_post_thumbnail_url($post_id = false) {
global $post;
if (!$post_id) {
$post_id = $post->ID;
}
$thumbnail_id = get_post_thumbnail_id($post_id);
echo wp_get_attachment_url($thumbnail_id);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment