How to add custom media library mime icons?
Can't seem to get wp_mime_type_icon
filter to work so I can use custom image for icons in the Media Library for documents. @birgire answered this post with the following code, but it does not seem to work in current WordPress version.
add_filter( 'wp_mime_type_icon', function( $icon, $mime, $post_id )
{
if( 'application/pdf' === $mime $post_id 0 )
$icon = 'http://example.tld/pdf.png'; // Modify this to your needs!
return $icon;
}, 10, 3 );
This throws an error failed to open stream: No such file or directory
and points to the core functions file in wp-includes
and a second exif error that it's trying to find the file in /wp-includes/images/media/
and ignoring the custom path.
I tried hard-coding the $icon
path or using get_template_directory_uri() . '/my/path/pdf.png'
but this also failed with the same errors. For some reason it's ignoring the path.
I just want to replace all of the images in /wp-includes/images/media/
with my own that reside in my theme. I only really need text/plain
and application/pdf
, but would be nice to know how to target them all, or just redirect to a different folder with same-named files.
Edit: I just noticed that this seems to work in grid view. In List view, the errors are thrown and the custom image is not used. I need it to work in both. Maybe it's a bug.
Topic mime-types media-library filters media hooks Wordpress
Category Web