Last active
June 15, 2016 19:25
-
-
Save shizhua/14e6bacd7ba43fee0a70 to your computer and use it in GitHub Desktop.
List all image sizes in a WordPress post
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 | |
/** | |
* List all image sizes in a WordPress post | |
* by Leo | |
* URL: http://wpsites.org/?p=10617 | |
*/ | |
$images = array(); | |
$image_sizes = get_intermediate_image_sizes(); | |
array_unshift( $image_sizes, 'full' ); | |
$img_id = get_post_thumbnail_id( get_the_ID() ); | |
if ( $img_id ) { | |
echo 'Downloads: '; | |
foreach( $image_sizes as $image_size ) { | |
$image = wp_get_attachment_image_src( $img_id, $image_size ); | |
$name = $image_size . ' (' . $image[1] . 'x' . $image[2] . ')'; | |
$images[] = '<a href="' . $image[0] . '" target="_blank">' . $name . '</a>'; | |
} | |
echo implode( ' | ', $images ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment