Skip to content

Instantly share code, notes, and snippets.

@shizhua
Last active June 15, 2016 19:25
Show Gist options
  • Save shizhua/14e6bacd7ba43fee0a70 to your computer and use it in GitHub Desktop.
Save shizhua/14e6bacd7ba43fee0a70 to your computer and use it in GitHub Desktop.
List all image sizes in a WordPress post
<?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