The media_view_settings WordPress PHP filter allows you to modify the media view settings in the WordPress admin area.
Usage
add_filter( 'media_view_settings', 'my_custom_media_view_settings', 10, 2 ); function my_custom_media_view_settings( $settings, $post ) { // your custom code here return $settings; }
Parameters
$settings
(array) – List of media view settings.$post
(WP_Post) – Post object.
More information
See WordPress Developer Resources: media_view_settings
Examples
Change the default gallery link setting
This example changes the default gallery link setting to “Media File” instead of “Attachment Page”:
add_filter( 'media_view_settings', 'change_default_gallery_link', 10, 2 ); function change_default_gallery_link( $settings, $post ) { $settings['galleryDefaults']['link'] = 'file'; return $settings; }
Change the default gallery columns setting
This example changes the default gallery columns setting to 4 columns:
add_filter( 'media_view_settings', 'change_default_gallery_columns', 10, 2 ); function change_default_gallery_columns( $settings, $post ) { $settings['galleryDefaults']['columns'] = 4; return $settings; }
Disable the “Uploaded to this post” filter
This example disables the “Uploaded to this post” filter in the media library:
add_filter( 'media_view_settings', 'disable_uploaded_to_this_post_filter', 10, 2 ); function disable_uploaded_to_this_post_filter( $settings, $post ) { $settings['library']['uploadedTo'] = false; return $settings; }
Change the default image size setting
This example changes the default image size setting to “medium”:
add_filter( 'media_view_settings', 'change_default_image_size', 10, 2 ); function change_default_image_size( $settings, $post ) { $settings['galleryDefaults']['size'] = 'medium'; return $settings; }
Set the default orderby setting
This example sets the default orderby setting for media library items to “title” in ascending order:
add_filter( 'media_view_settings', 'set_default_orderby_setting', 10, 2 ); function set_default_orderby_setting( $settings, $post ) { $settings['library']['orderby'] = 'title'; $settings['library']['order'] = 'ASC'; return $settings; }