Take the 2-minute tour ×
WordPress Development Stack Exchange 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 pinpoint one media file by the file name, but file name 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 file name, so I can find the correct URL to this image.

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

I can't search the media library by file name 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 –  user27545 Feb 15 '13 at 21:00
add comment

2 Answers 2

up vote 4 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 '13 at 10:43
1  
functions.php of course! :) –  Bart Karp Feb 3 '13 at 0:05
add comment

I'm not sure if this answers the question directly but I was trying to get a "URL" column on the Media Library page (to avoid clicking the edit link every time...) and found this code snippet which does exactly that.

I played with it a little to get it to sort the URLs alphabetically and to strip the domain, to improve my workflow a bit more. Check it out:

<?php
function muc_column($cols) {
    $cols["media_url"] = "URL";
    return $cols;
}

function muc_value($column_name, $id) {
    if ($column_name == "media_url")

    $subject = wp_get_attachment_url($id);
    $grab = array("http://example.com", "http://another.example.com");
    $replaceWith = '';
    $path = str_replace($grab, $replaceWith, $subject);

    echo '<input
                type="text"
                width="100%"
                onclick="jQuery(this).select();"
                value="'.$path.'" />';
}

function muc_column_sortable($cols) {
    $cols["media_url"] = "name";
    return $cols;
}

add_filter('manage_media_columns', 'muc_column');
add_action('manage_media_custom_column', 'muc_value', 10, 2);
add_filter('manage_upload_sortable_columns', 'muc_column_sortable'); 
?>

I should mention it also presents the URL in an <input> that automatically selects the text when clicked, a nice feature for a quick copy and paste.

share|improve this answer
add comment

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.