Skip to content

Instantly share code, notes, and snippets.

@abelcallejo
Last active April 18, 2020 08:52
Show Gist options
  • Save abelcallejo/f4dd656d1b73bd7af0bd4d0b0187a011 to your computer and use it in GitHub Desktop.
Save abelcallejo/f4dd656d1b73bd7af0bd4d0b0187a011 to your computer and use it in GitHub Desktop.
Adding screen options on Wordpress

Adding screen options on Wordpress

functions.php

function register_submenu_screen() {
    global $pagenow;

    if( $pagenow == 'options-general.php' && isset($_GET['page']) && $_GET['page']=='integrations' ) {
        $screen = get_current_screen();
        add_filter( 'screen_layout_columns', 'embed_submenu_screen' );
        $screen->add_option('submenu_screen', '');
    }
}

function embed_submenu_screen() {
	echo "Hello world!";
}

add_action( 'admin_head', 'register_submenu_screen' );

Sample markup of a typical screen

<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="Screen Options Tab" style="display: block;">
	<form id="adv-settings" method="post">
		<fieldset class="metabox-prefs">
			<legend>Columns</legend>
			<label><input class="hide-column-tog" name="author-hide" type="checkbox" id="author-hide" value="author" checked="checked">Author</label>
			<label><input class="hide-column-tog" name="comments-hide" type="checkbox" id="comments-hide" value="comments" checked="checked">Comments</label>
			<label><input class="hide-column-tog" name="date-hide" type="checkbox" id="date-hide" value="date" checked="checked">Date</label>
		</fieldset>
		<fieldset class="screen-options">
			<legend>Pagination</legend>
			<label for="edit_page_per_page">Number of items per page:</label>
			<input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]" id="edit_page_per_page" maxlength="3" value="20">
			<input type="hidden" name="wp_screen_options[option]" value="edit_page_per_page">
		</fieldset>
		<p class="submit"><input type="submit" name="screen-options-apply" id="screen-options-apply" class="button button-primary" value="Apply"></p>
	</form>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment