Skip to content

Instantly share code, notes, and snippets.

@willthemoor
Last active August 31, 2015 23:15
Show Gist options
  • Save willthemoor/5308185afac10a0d7c72 to your computer and use it in GitHub Desktop.
Save willthemoor/5308185afac10a0d7c72 to your computer and use it in GitHub Desktop.
WordPress: Add URLs for all generated image sizes to Media Library listing
<?php
/*
* Include the URLs for all image sizes in the WordPress Media Library.
* Not normally needed but if you're trying to gather a bunch of URLs it helps.
* Hide the column in Screen Options when not needed.
*
* Drop this in your site plugin or function.php
*/
// 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) {
echo "<strong>" . $name . "</strong><br>";
echo "<small>" . $dir . "/" . $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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment