Skip to content

Instantly share code, notes, and snippets.

@dmitry-korolev
Created September 22, 2015 17:25
Show Gist options
  • Save dmitry-korolev/5424dfa9babc55acc4b5 to your computer and use it in GitHub Desktop.
Save dmitry-korolev/5424dfa9babc55acc4b5 to your computer and use it in GitHub Desktop.
Returns urls of all sizes of the post thumbnail (featured image).
<?php
/**
* Returns urls of all sizes of the post thumbnail (featured image).
* @param integer $post_id Post ID
* @return array Key-value array of sizes and urls.
*/
function md_post_thumbnail_urls($post_id) {
$thumbnail_id = get_post_thumbnail_id( $post_id );
if ($thumbnail_id === '') {
return;
}
$sizes = get_intermediate_image_sizes();
$sizes[] = 'full';
$urls = [];
foreach($sizes as $size){
$urls[$size] = wp_get_attachment_image_src( $thumbnail_id, $size )[0];
}
return $urls;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment