How to remove list view from media library?

This is a little hacky, but doesn’t require you to edit core files, which you should never do, as you are aware.

add_action('admin_init', function() {
    $_GET['mode'] = 'grid';
}, 100);

This will always force the mode into grid view.

What it does not do,

  • it does not remove the List View icon
  • it does not change the query argument in the URL

To remove the List View icon you can do something to the effect of:

add_action('admin_head', function() {

    ?>

    <style type="text/css">
        .view-switch .view-list {
            display: none;
        }
    <style>

    <?php

});

Alternatively, to remove the ?mode=list query argument from the URL, you could:

  • use JavaScript to modify the search property found on windlow.location
  • redirect the user server side using wp_redirect() by inspecting $_GET super global for the mode query variable array key (recommended).

For example you could rewrite the first snippet to:

add_action('admin_init', function() {

    if ( isset( $_GET['mode'] ) && $_GET['mode'] !== 'grid' ) {
        wp_redirect(admin_url('upload.php?mode=grid'));
        exit;
    } else {
        //required by upload.php, handle the case if user just navigates to... 
        //http://www.example.com/wp-admin/upload.php (with no mode query argument)
        $_GET['mode'] = 'grid';
    }

}, 100);

Or alternativey without the need for an else block,

add_action('admin_init', function() {

    if ( strpos(admin_url('upload.php'), $_SERVER['REQUEST_URI']) !== false 
         || (isset($_GET['mode']) && $_GET['mode'] === 'list') ) {
        wp_redirect(admin_url('upload.php?mode=grid'));
        exit;
    } 

}, 100);

…the above snippet ensures that no matter what, either of the following URLs,

…will always be redirected to,

Combined with hiding the List View icon via injecting CSS on the admin_head hook, produces the desired result you are after.

Leave a Comment