1

My client wants to be able to see the filenames of his images in the media browser (not the media library, the browser when you are adding media to a post or page). I used this snippet to do that a couple years ago, but it no longer works in WordPress 4.1 and I can't quite pinpoint why.

The code I have:

add_action( 'in_admin_footer', 'my_wrap_media_template_callback', 10, 0 );

function wp_print_media_templates_wrapper() {
    ob_start();
    wp_print_media_templates();
    $output = ob_get_clean();

    // Finding the correct spot to insert
    $to_find = '
        <div class="thumbnail">
            <div class="centered">
                <img src="{{ data.size.url }}" draggable="false" />
            </div>
        </div>';
    // HTML that will render filename
    $to_add = '
                <div class="filename">
                    <div>{{ data.filename }}</div>
                </div>';
    $output = str_replace( $to_find, $to_find . $to_add, $output );
    echo $output;
}

I guess in theory I could try something like this, where I recreate the whole function + my little adjustment. That seems very excessive though.

How can I update this code to work with WP 4.1?

An image of what I'm trying to do:

enter image description here

[UPDATE 10/19] Ok, so I couldn't find the hook I wanted to rewrite this code with so I edited core files instead and I got it working! In the wp-includes/media-template.php, I added a line directly after 452:

<div class="filename"><strong><?php _e( 'File name:' ); ?></strong> {{ data.filename }}</div>

And that put filenames exactly how I wanted them in my media browser (after forcing them to regenerate, because it was only applying to newly uploaded files and not images uploaded because the code adjustment).

So now I'm trying to figure out how to put this into my functions.php file so I don't have to keep this core file edited. I only really need help identifying the hook I need to call. Can anyone help me with this? Thank you!

  • add some images to understand more! – Webloper Oct 7 '15 at 22:39
  • I added a picture of what I'm attempting to do. Does this help? Thanks! – Chloe LaPointe Oct 8 '15 at 23:22
  • What hook were you using before? The Media Library got a massive overhaul several releases ago. You probably just need to change to the new equivalent hook. – Matt van Andel Oct 9 '15 at 1:37
  • @MattvanAndel omg I missed a line of code when I posted this! I edited my main post with the forgotten line at the top! I'm so sorry, and thank you for pointing it out to me! – Chloe LaPointe Oct 10 '15 at 0:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.