Jean-Marc Amiaud

Replace WordPress default media icon with preview image

by on Mar.05, 2011, under Programmation, WordPress

Media library in WordPress display thumbnail of the pictures but only generic icon for all other type.
It’s possible to change generics icons (eg. by video preview image) with pair of filter :

[code lang= »csharp »]

add_filter(‘wp_mime_type_icon’, ‘my_plugin_video_icon’, 10, 3);
add_filter(‘icon_dir’, ‘wp_plugin_video_icon_dir’);

function my_plugin_video_icon($icon, $mime, $post_id)
                 // – Find your icon for the specified post
                 // – Save the repository of your icon as global
                global $_current_video_icon_dir;
                $_current_video_icon_dir =  dirname(ABSPATH . substr($new_icon, strpos($new_icon, "wp-content")));

                // – Return your icon path
                return $new_icon;

function my_plugin_video_icon_dir($dir)
        global $_current_video_icon_dir;

                $var = $_current_video_icon_dir;
                $_current_video_icon_dir = null;
                return $var;
        return $dir;


:, , , ,

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!