• hi

    would it be possible from functions.php to show the name of the image in the media page (grid)?

    many thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Topher

    (@topher1kenobe)

    Just adding it to the grid wouldn’t look very good, but I noticed that none of those images have alt text. I’d look at the source code for what’s making the grid and see if you can hook into the image rendering and put the filename in the alt text. You wouldn’t see them all the time, but you could hover over them and see it in a tooltip.

    Thread Starter kaquna

    (@kaquna)

    thank you for your response.

    I can get it through jquery (with my low level, something I can do) and it looks good depending on the css applied to it.
    I don’t know too much about php, so I don’t know how I could do it.
    with jQuery, as the library seems to be loaded via ajax, I have to do a settimeout and execute the function every time you scroll…

    
    <script>
    function name_in_media() {
    	jQuery('ul.attachments > li').each(function(){
    		var img = jQuery(this);
    		var nm = img.attr('aria-label');
    		var divnm = '<div class="name">' + nm + '</div>';
    		if (img.find('.name').length > 0) {
    			// nothing
    		} else { img.append(divnm); }
    	});
    }
    
    setTimeout(name_in_media,2000);
    jQuery(window).scroll(function(e){ name_in_media(); });
    
    </script>
    
    <style>
    .name{line-height:1.2;min-height:42px;overflow-wrap:break-word;margin-top:5px}
    </style>
    
    

    I know this is not very usefull… besides, when replace an image in image wp-block in gutenberg it doesn’t work…

    • This reply was modified 3 years, 8 months ago by kaquna.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘display names in media page’ is closed to new replies.