Get URLs for All Sizes of Image via Admin Panel

We want to use wordpress to host image which we’ll use in our email newsletter.

To that end, we can obviously upload the image via the Media panel in Admin and either right-click the image and get URL or enter Library and click the image to see the URL in the details area.

Then we could manually add the thumbnail size based on theme/settings:

a_full_url/image.150x150.ext

And of course we could add the Medium or Large image into a Post or Page and right-click).

Is there an easier way, via the GUI that an administrator can view/get the various sizes for an image?

2 Answers
2

This is a good idea. Thanks for suggesting it—going to use it. 🙂

You can add a column to the Media Library that outputs the paths. This will spit them all out. You could of course filter it to only show the sizes you actually want. Put in functions.php or similar.

// Adds a "Sizes" column
function sizes_column( $cols ) {
        $cols["sizes"] = "Sizes";
        return $cols;
}

// Fill the Sizes column
function sizes_value( $column_name, $id ) {
    if ( $column_name == "sizes" ) {
        // Including the direcory makes the list much longer 
        // but required if you use /year/month for uploads
        $up_load_dir =  wp_upload_dir();
        $dir = $up_load_dir['url'];

        // Get the info for each media item
        $meta = wp_get_attachment_metadata($id);

        // and loop + output
        foreach ( $meta['sizes'] as $name=>$info) {
            // could limit which sizes are output here with a simple if $name ==
            echo "<strong>" . $name . "</strong><br>";
            echo "<small>" . $dir . "https://wordpress.stackexchange.com/" . $info['file'] . " </small><br>";
        }
    }
}

// Hook actions to admin_init
function hook_new_media_columns() {
    add_filter( 'manage_media_columns', 'sizes_column' );
    add_action( 'manage_media_custom_column', 'sizes_value', 10, 2 );
}
add_action( 'admin_init', 'hook_new_media_columns' )

Using <small> as a quick and dirty hack to keep the size of long URLs in check. In production I’d probably make this a <dl> and add some admin CSS to adjust its display via site plugin.

enter image description here

Leave a Comment