Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Default Screen Options in Wordpress

Tags:

wordpress

I'm looking for a way to change the default screen options in the post editor. I want to hide certain options by default. I am putting together a family recipe site and don't want to overwhelm users with too many options. I don't want to log in as each user and changing their options manually. I've combed through WP core files and theme files and can't find very many references to screen-options. Is it defined somewhere in the database?

Thanks in advance.

like image 965
Maggy Mae Avatar asked Jun 28 '14 21:06

Maggy Mae


People also ask

Where is the screen options menu in WordPress?

Screen Options is a fly down menu button located on the top right corner of some pages in your WordPress admin area. When clicked, Screen Options menu shows options to configure the view of that particular page in your admin area. It usually contains check boxes to show and hide different sections of an admin screen.

How do I turn off screen options in WordPress?

In that tab, you need to click on the new 'Global Options' tab to expand it as well. You will see a bunch of options to show and hide in your WordPress admin area. You need to check the boxes next to 'Screen Options to disable the screen options button for any specific user roles.

Where are screen options in Gutenberg?

The Screen Options in Gutenberg are moved to a semi-hidden place and are just called “Options” now. You can find them by clicking the 3 vertical dots in the upper right, which opens a menu.


3 Answers

Use the default_hidden_meta_boxes filter

add_filter( 'default_hidden_meta_boxes', 'my_hidden_meta_boxes', 10, 2 );
function my_hidden_meta_boxes( $hidden, $screen ) {
    return array( 'tagsdiv-post_tag', 'tagsdiv', 'postimagediv', 'formatdiv', 'pageparentdiv', ''); // get these from the css class
}

or

add_filter( 'hidden_meta_boxes', 'my_hidden_meta_boxes', 10, 2 );

Bonus: To understand how it works have a look at the core function get_hidden_meta_boxes(). Here's a simplified version:

function get_hidden_meta_boxes( $screen ) {
    $hidden = get_user_option( "metaboxhidden_{$screen->id}" );
    if ( $use_defaults ) {
        $hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen );
    }
    return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults );
}
like image 139
zendka Avatar answered Oct 19 '22 09:10

zendka


The default screen options are saved in wp_usermeta the meta_key is metaboxhidden_post.

I think the easiest way to set default options (or to hide specific boxes) would be to use a plugin like adminimize. I personally use the advanced custom fields plugin for this task (and a lot more).

like image 37
alpipego Avatar answered Oct 19 '22 08:10

alpipego


A slight modification to Zendka's answer. I just wanted to remove one item from the list, leaving the array otherwise unchanged.

add_filter( 'default_hidden_meta_boxes', 'show_author_metabox', 10, 2 );
function show_author_metabox( $hidden, $screen )
{
    $authorkey = array_search( 'authordiv', $hidden );
    unset( $hidden[ $authorkey ] );

    return $hidden;
}

In my case I was removing the 'authordiv' from the hidden list, swap that out with whatever metabox you want to remove from the hidden meta boxes.

I don't check for the existence of the metabox before unsetting it, because it doesn't produce any PHP notices/errors if there are no results from the array_search.

like image 2
Matt Keys Avatar answered Oct 19 '22 09:10

Matt Keys