Tag: Preview
Replace WordPress default media icon with preview image
by Jean-Marc Amiaud le 05 Mar 2011, catégorie 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)
{
if(preg_match("/^video/",$mime))
{
// – 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;
if(!empty($_current_video_icon_dir))
{
$var = $_current_video_icon_dir;
$_current_video_icon_dir = null;
return $var;
}
return $dir;
}
[/code]