• Ok, so I had a website where I wanted to display filenames on top of each image thumbnail in the grid view for the media Library browser. I found this snippet: https://xplus3.net/2013/09/26/add-file-name-wordpress-media-browser/ , tried it, and for the life of me could not get it to work without breaking the media browser entirely (clicking on the add media button would do nothing).

    In a desperate attempt, I altered the Media-template core file by adding

    <div class="filename">
    {{ data.filename }}
    </div>

    underneath the image thumbnail call.
    This worked for WordPress 4.2 and 4.3, but with the upgrade to 4.4 I cannot for the life of me get the filename to display on the thumbnails. I would revert back to 4.3 and use my old core file, but it got lost in the site launch and now I’m stuck.

    This https://i.stack.imgur.com/6yMIX.png is an image of what I’m trying to make happen.

    If anyone has any idea why my hack no longer works, or if there’s a better way to handle this, please let me know!

    Thanks in advance for the help!

    (also if this is the wrong subforum for this, I’m sorry!)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    I don’t have the answer you seek, but I can suggest how to accomplish something without a core hack once you do identify the solution.

    Your experience is exactly one reason why altering core files is so strongly discouraged. The other is people forgo updates to avoid losing their hacks, which has significant security ramifications. There is nothing that is so important that it warrants a core hack. Nothing.

    There’s nearly always a clean way to do something, and if not it’s something you can live without. What? It really is that important? Then submit an enhancement proposal to Trac. If it really is so important, then it is a good candidate for official incorporation into core.

    The media template file is mostly Backbone script, which gets output as JavaScript. You can override JS by loading your own function of the same name later than the core script. If all else fails, you can make things happen with jQuery, altering the HTML as needed after the page is output.

    Thread Starter ashikai

    (@ashikai)

    Thanks for the reply. I do get what you’re saying and honestly this was the very first time I’d ever altered the core files and it was just as a bandaid until I could figure out how to do what I wanted without it. Is it something I can live without, yes, but this was a client website and it’s not something they feel they can live without, so I’m a bit stuck.

    The link I supplied in the OP was to a snippet that worked in WordPress 3.7-3.9 but I think the code that it looks for and adjusts has changed and I can’t figure out where. That becomes my fundamental problem. ??

    Moderator bcworkz

    (@bcworkz)

    The part of media-template.php that outputs the thumbnails starts around line 446. There is no clean way in this file to alter that portion. The best chance for a clean solution is using jQuery to locate all the thumbnails and extract the filename from the src attribute, then append it to the outer container HTML.

    This cannot happen until the script renders the thumbnails of course. I’m unsure how to coordinate the two scripts, but I think this is the best direction to pursue.

    Thread Starter ashikai

    (@ashikai)

    Hmmm I see… I’ve never done that before so I’ve got no clue where to start. But thanks for the input! I’ll do some research and see what I can find out.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display filenames in Media Library Grid View’ is closed to new replies.