Created
September 22, 2015 17:25
-
-
Save dmitry-korolev/5424dfa9babc55acc4b5 to your computer and use it in GitHub Desktop.
Returns urls of all sizes of the post thumbnail (featured image).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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