X

Add custom tab to featured image media library popup

Adding this snippet to the functions.php of your wordpress theme will add a new tab to the featured image popup called mime types. Clicking on this tab will display a list of the allowed file types however this could be changed to display almost any information.


As requested by Cor van Noorloos, I added a screenshot to better explain the snippet. ( view screenshot ).


Code Snippet:


function mime_type_tab($tabs) {
/* name of custom tab */
$new_tab = array('mimeframe' => __('Mime Types', 'mimetype'));
return array_merge($tabs, $new_tab);
}
add_filter('media_upload_tabs', 'mime_type_tab');

function create_mime_type_page() {
media_upload_header();
wp_enqueue_style( 'media' );

/* add custom code to display bellow this line */
/* display mime types */
$mimes = get_allowed_mime_types();
$types = array();

echo '<div class="type-outer">';
echo '<h3 class="media-title">Supported file types</h3>';
echo '<hr />';

foreach ($mimes as $ext => $mime) {
$types[] = '<li>' . str_replace('|', ', ', $ext) . '</li>';
}
echo '<ul class="mime-types">' . implode('', $types) . '</ul>';
echo '</div>';
/* end custom code */

}

function insert_mime_type_iframe() {
return wp_iframe( 'create_mime_type_page');
}
add_action('media_upload_mimeframe', 'insert_mime_type_iframe');

add_action( 'admin_head', 'mime_frame_css' );
function mime_frame_css() {
echo '<style type="text/css">
.type-outer{margin:20px;}
.type-outer hr{
border:solid #ccc;
border-width:0px 0px 1px 0px;
margin:0px 0px 20px 0px;
}
.mime-types li{
font-size:10px;
float:left;
width:24%;
padding:1px;
}
</style>';
}

Comments  Leave a Reply

  1. cool, how can we set it as the default tab?

  2. thanks for this….. it’s great..

    1.  Cool glad to see that I could help.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!