Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement