add_screen_option() wordpress function and usage This text is not used because the data attribute has a value

add_screen_option() wordpress function and usage

Home / WordPress / WordPress Wiki / add_screen_option() wordpress function and usage

add_screen_option( string $option, mixed $args = array() )
Register and configure an admin screen option

Parameters

$option

(string) (Required) An option name.

$args

(mixed) (Optional) Option-dependent arguments.

Default value: array()

Sample Usage

Example

Change default columns for network dashboard

add_action( 'wp_network_dashboard_setup', function() {
    add_screen_option( 'layout_columns', array( 'default' => 2 ) );
} );

The $option parameter define the object (input or radio button) which will be printed to the screen option section.

add_screen_option only accept 2 methods:

  • 1. ‘per_page’
  • 2. ‘layout_columns’

Example 1:

add_screen_option( 'per_page', array( 'label' => 'My Label', 'default' => 1, 'option' => 'option_name' ) );
will print
<input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]" id="option_name" maxlength="3" value="1">

Example 2:

add_screen_option( 'layout_columns', array( 'max' => 2, 'default' => 2 ) );
will print

1
2
<input type="radio" name="screen_columns" value="1">
<input type="radio" name="screen_columns" value="2" checked="checked">

add_screen_option not support the checkboxes method yet.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments