The media_upload_default_tab WordPress PHP filter allows you to change the default tab in the legacy (pre-3.5.0) media popup.
Usage
add_filter('media_upload_default_tab', 'your_custom_function'); function your_custom_function($tab) { // your custom code here return $tab; }
Parameters
$tab
(string) – The default media popup tab. Default ‘type’ (From Computer).
More information
See WordPress Developer Resources: media_upload_default_tab
Examples
Change default tab to Media Library
Set the default tab to ‘library’ (Media Library) instead of ‘type’ (From Computer).
add_filter('media_upload_default_tab', 'change_default_media_tab_to_library'); function change_default_media_tab_to_library($tab) { return 'library'; }
Set default tab based on user role
Change the default tab based on the user’s role. Administrators will see the ‘library’ tab, while other users will see the ‘type’ tab.
add_filter('media_upload_default_tab', 'change_default_media_tab_based_on_role'); function change_default_media_tab_based_on_role($tab) { if (current_user_can('administrator')) { return 'library'; } else { return 'type'; } }
Set default tab based on custom capability
Set the default tab to ‘library’ for users with a custom capability called ‘view_media_library’.
add_filter('media_upload_default_tab', 'change_default_media_tab_based_on_capability'); function change_default_media_tab_based_on_capability($tab) { if (current_user_can('view_media_library')) { return 'library'; } else { return 'type'; } }
Change default tab to URL
Set the default tab to ‘url’ (Insert from URL) instead of ‘type’ (From Computer).
add_filter('media_upload_default_tab', 'change_default_media_tab_to_url'); function change_default_media_tab_to_url($tab) { return 'url'; }
Set default tab based on post type
Change the default tab based on the post type. For ‘gallery’ post type, set the default tab to ‘gallery’.
add_filter('media_upload_default_tab', 'change_default_media_tab_based_on_post_type'); function change_default_media_tab_based_on_post_type($tab) { global $post; if ($post->post_type == 'gallery') { return 'gallery'; } else { return 'type'; } }