Using WordPress ‘media_upload_tabs’ PHP filter

The media_upload_tabs WordPress PHP filter allows you to modify the available tabs in the legacy media popup (pre-3.5.0).

Usage

add_filter('media_upload_tabs', 'your_custom_function');
function your_custom_function($_default_tabs) {
    // your custom code here
    return $_default_tabs;
}

Parameters

  • $_default_tabs (array): An array of media tabs.

More information

See WordPress Developer Resources: media_upload_tabs

Examples

Add a Custom Tab

Add a custom tab named “Custom Tab” to the media popup.

add_filter('media_upload_tabs', 'add_custom_media_tab');
function add_custom_media_tab($_default_tabs) {
    $_default_tabs['custom_tab'] = 'Custom Tab';
    return $_default_tabs;
}

Remove a Tab

Remove the “Gallery” tab from the media popup.

add_filter('media_upload_tabs', 'remove_gallery_media_tab');
function remove_gallery_media_tab($_default_tabs) {
    unset($_default_tabs['gallery']);
    return $_default_tabs;
}

Reorder Tabs

Reorder the tabs by moving the “Media Library” tab to the first position.

add_filter('media_upload_tabs', 'reorder_media_tabs');
function reorder_media_tabs($_default_tabs) {
    $_media_library = $_default_tabs['library'];
    unset($_default_tabs['library']);
    $_default_tabs = array('library' => $_media_library) + $_default_tabs;
    return $_default_tabs;
}

Rename a Tab

Rename the “Media Library” tab to “Your Library”.

add_filter('media_upload_tabs', 'rename_media_library_tab');
function rename_media_library_tab($_default_tabs) {
    $_default_tabs['library'] = 'Your Library';
    return $_default_tabs;
}

Conditionally Remove a Tab

Remove the “Gallery” tab only for a specific user role.

add_filter('media_upload_tabs', 'conditionally_remove_gallery_tab');
function conditionally_remove_gallery_tab($_default_tabs) {
    if (current_user_can('editor')) {
        unset($_default_tabs['gallery']);
    }
    return $_default_tabs;
}