Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've migrated hosts for a Wordpress site, and a lot of my images have the same title.

I am trying to pin point one media file by the filename, but filename is not a column listed in Media Library.

I don't want to have to wade through dozens of images with the same title trying to find the problem filename, so I can find the correct URL to this image.

How can I add filename to the list of columns in Media Library?

I can't search the media library by filename either.

share|improve this question
You can also try my plugin, Media Library Assistant. It has a wide variety of features that help you find images, including the ability to add file name as a sortable column. wordpress.org/extend/plugins/media-library-assistant – David Lingren Feb 15 at 21:00

1 Answer

up vote 3 down vote accepted

Here you go, this code not only lists all filenames in Library but also allows you to sort them by name:

// Add the column
function filename_column( $cols ) {
        $cols["filename"] = "Filename";
        return $cols;
}

// Display filenames
function filename_value( $column_name, $id ) {
    $meta = wp_get_attachment_metadata($id);
           echo substr( strrchr($meta['file'], '/' ), 1); 
          //Used a few PHP functions cause 'file' stores local url to file not filename
}

// Register the column as sortable & sort by name
function filename_column_sortable( $cols ) {
    $cols["filename"] = "name";

    return $cols;
}


// Hook actions to admin_init
function hook_new_media_columns() {
    add_filter( 'manage_media_columns', 'filename_column' );
    add_action( 'manage_media_custom_column', 'filename_value', 10, 2 );
    add_filter( 'manage_upload_sortable_columns', 'filename_column_sortable' );
}
add_action( 'admin_init', 'hook_new_media_columns' );
share|improve this answer
what file do I add this code to? – Steve Feb 2 at 10:43
1  
functions.php of course! :) – Bart Karp Feb 3 at 0:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.