Add a Sub-Menu
add_submenu_page( string $parent_slug, string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '' );
Example
<div>
wrap
function wporg_options_page_html() { // check user capabilities if ( ! current_user_can( 'manage_options' ) ) { return; } ?> <div class="wrap"> <h1><? php echo esc_html( get_admin_page_title() ); ?></ h1> <form action="options.php" method="post"> <? php // output security fields for the registered setting "wporg_options" settings_fields( 'wporg_options' ); // output setting sections and their fields // (sections are registered for "wporg", each field is registered to a specific section) do_settings_sections( 'wporg' ); // output save settings button submit_button( __( 'Save Settings', 'textdomain' ) ); ?> </form> </div> <? php }
function wporg_options_page() { add_submenu_page( 'tools.php', 'WPOrg Options', 'WPOrg Options', 'manage_options', 'wporg', 'wporg_options_page_html' ); } add_action('admin_menu', 'wporg_options_page');
Predefined Sub-Menus
-
add_dashboard_page() – index.php -
add_posts_page() – edit.php -
add_media_page() – upload.php -
add_pages_page() – edit.php?post_type=page -
add_comments_page() – edit-comments.php -
add_theme_page() – themes.php -
add_plugins_page() – plugins.php -
add_users_page() – users.php -
add_management_page() – tools.php -
add_options_page() – options-general.php -
add_options_page() – settings.php -
add_links_page() – link-manager.php – requires a plugin since WP 3.5+ -
Custom Post Type – edit.php?post_type=wporg_post_type -
Network Admin – settings.php
Remove a Sub-Menu
Submitting forms
function wporg_options_page() { $hookname = add_submenu_page( 'tools.php', 'WPOrg Options', 'WPOrg Options', 'manage_options', 'wporg', 'wporg_options_page_html' ); add_action( 'load-' . $ hookname, 'wporg_options_page_html_submit' ); } add_action('admin_menu', 'wporg_options_page');