X

Add Custom Tab to Featured Image Media Library Popup

Snippets by IsItWP

Are you looking for a way to add a new tab to the featured image popup? While there’s probably a plugin for this, we have created a quick code snippet that you can use to add custom tab to featured image media library popup in WordPress.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

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>';
	}

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 8 best WordPress review plugins to boost online revenue and how to create a multi-page form in WordPress.

Comments   Leave a Reply

  1. Hi there, I know this is an old one, but maybe someone can still help. It doesn’t work for me, no change in the media popup after inserting this code to my functions.php – any ideas?

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

  3. 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!