Home / functions.php / Linking to all image sizes Flickr style
  • How to Linking to all image sizes Flickr style


    Adding this snippet to your wordpress theme will automatically link to all image sizes. Add the first snippet to the functions.php of your wordpress theme. Then add the second snippet to the image.php or attachment.php template of your wordpress theme.

    ( click code to copy )

    wordpress snippet : PHP - functions.php

    function my_get_image_size_links() {
    	if ( !wp_attachment_is_image( get_the_ID() ) )
    	$links = array();
    	$sizes = get_intermediate_image_sizes();
    	$sizes[] = 'full';
    	foreach ( $sizes as $size ) {
    		$image = wp_get_attachment_image_src( get_the_ID(), $size );
    		if ( !empty( $image ) && ( true == $image[3] || 'full' == $size ) )
    			$links[] = "<a class='image-size-link' href='{$image[0]}'>{$image[1]} &times; {$image[2]}</a>";
    	return join( ' <span class="sep">/</span> ', $links );
    ( click code to copy )

    wordpress snippet : PHP

    <?php if ( wp_attachment_is_image( get_the_ID() ) ) { ?>
    	<div class="image-meta">
    		<?php printf( __( 'Sizes: %s', 'example-textdomain' ), my_get_image_size_links() ); ?>
    <?php } ?>
  • Kevin, I was looking for something like this a few weeks ago and gave up after not finding a simple solution for a code-dummy like me. Lucky to have stumbled across your blog though, gonna go try it! =)

    • cool glad I could help out! don’t forget to follow us I post new snippets daily!

  • Riffat Malik

    This is awesome!! love this..!

  • Thomas

    Thanks for this snippet – works great! I’m trying to display only certain images sizes but had no success so far. Any hint how to do that?

    Also I’d like to show these links on the single post template…

    • Hi Thomas, well $sizes is an array you could add a statement within foreach to only display specific sizes.

      • Thomas

        Ok, I see, thanks! And regarding the display on the single post template?


  • Stew

    not work aniway