Getting started with WordPressget_bloginfo()Enqueuing scriptsMaking network requests with HTTP APIEnqueuing Styleshome_url()Custom Post Typestemplate_includeThe Loop (main WordPress loop)AJAXThe $wpdb ObjectActions and Filterswp_get_current_user()Add/remove contact info for users with user_contactmethods filter hookCreating a custom templateCustomizer Hello WorldCustomizer Basics (Add Panel, Section, Setting, Control)The Admin Bar (aka "The Toolbar")Querying postsAlternating main loop (pre_get_posts filter)ShortcodeCreate a Post Programmaticallyget_template_part()Taxonomiesget_template_part()ShortcodesPost FormatsCustom exerpts with excerpt_length and excerpt_morePlugin developmentSecurity in WordPress - EscapingTemplate hierarchyRemove Version from Wordpress and StylesheetsChild Theme Basicsadd_action()get_template_part()Shortcode with attributeSidebarsSecurity in WordPress - SanitizationinitCreate Template for Custom Post TypeFunction: add_action()Add ShortcodeHow Can I integrate Markdown editor with Advance Custom Field's repeater Add-on.Installation and Configurationwp_get_current_user()WP-CronSecure your installationOptions APIFunction : wp_trim_words()WP_Query() LoopUpdate WordPress ManuallyThemesWP-CLIDebuggingadd_menu_page()add_submenu_page()get_option()get_permalink()get_the_category()the_title()get_the_title()add_editor_style()add_theme_support()WordPress Plugin creationRun WordPress local with XAMPPAdmin Dashboard WidgetsSite MigrationMeta BoxRemove Auto Line Breaks From Content and Excerptget_home_path()Wordpress theme and child-theme developmentREST API

add_submenu_page()

Other topics

Remarks:

Here are a list of slugs for $parent_slug

  • Dashboard: ‘index.php’
  • Posts: ‘edit.php’
  • Media: ‘upload.php’
  • Pages: ‘edit.php?post_type=page’
  • Comments: ‘edit-comments.php’
  • Custom Post Types: ‘edit.php?post_type=your_post_type’
  • Appearance: ‘themes.php’
  • Plugins: ‘plugins.php’
  • Users: ‘users.php’
  • Tools: ‘tools.php’
  • Settings: ‘options-general.php’
  • Network Settings: ‘settings.php’

Adding the "Submenu Page" as a sub-page of "Tools" to the nav bar

Code

add_action('admin_menu', 'register_my_custom_submenu_page');
 
function register_my_custom_submenu_page() {
    add_submenu_page(
        'tools.php',
        'Submenu Page',
        'My Custom Submenu Page',
        'manage_options',
        'my-custom-submenu-page',
        'my_custom_submenu_page_content' );
}
 
function my_custom_submenu_page_content() {
    echo '<div class="wrap">';
        echo '<h2>Page Title</h2>';
    echo '</div>';
}

Output

enter image description here

Explanation

In the code, we created a function named register_my_custom_submenu_page and we used add_submenu_page to add the item to the navbar as a child of tools.php, which is the Tools page.

Please check the parameters part in this page to know about the arguments we passed in. Then we used add_action to run our register_my_custom_submenu_page function. Finally, we created the function my_custom_submenu_page_content to display contents in the page.

Syntax:

  • add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function )

Parameters:

ParameterDetails
$parent_slug(string) The slug name for the parent menu (or the file name of a standard WordPress admin page).
$page_title(string) The text to be displayed in the title tags of the page when the menu is selected.
$menu_title(string) The text to be used for the menu.
$capability(string) The capability required for this menu to be displayed to the user.
$menu_slug(string) The slug name to refer to this menu by (should be unique for this menu).
$function(callable) (Optional) The function to be called to output the content for this page.

Contributors

Topic Id: 9193

Example Ids: 28541

This site is not affiliated with any of the contributors.