Create a Submenu Page in WordPress Admin
This can be useful when you plan on creating a simple plugin-like page that doesn’t require an installation, simply add the codes to your functions.php and it will appear right away on your admin page.
First we register our submenu by hooking it to the admin_menu
1 2 3 4 5 | add_action('admin_menu', 'register_custom_submenu'); function register_custom_submenu() { add_submenu_page( 'tools.php', 'Custom Submenu', 'Custom Submenu', 'administrator', 'custom-submenu', 'custom_submenu' ); } |
Let’s review the above code
1st Parameter of the add_submenu_page is the slug name for the parent menu (or the file name of a standard WordPress admin page). Use NULL or set to ‘options.php’ if you want to create a page that doesn’t appear in any menu.
2nd Parameter – the text to be displayed in the title tags of the page when the menu is selected
3rd Parameter – This is simply the text to be used for the menu
4th Parameter – The capability required for this menu to be displayed to the user. Check out the list of capabilities by following this link: List of Capabilities
5th Parameter – The slug name to refer to this menu by (should be unique for this menu). If you want to NOT duplicate the parent menu item, you need to set the name of the $menu_slug exactly the same as the parent slug.
6th Parameter – The function to be called to output the content for this page. The codex say this is not required, but of course we have to create this since this will be the function that will be outputting our page contents.
So now that we have registered our menu, we can simply create the function custom_submenu(); where we will be placing our contents
1 2 3 4 | function custom_submenu() { echo '<h2>Custom Submenu</h2>'; echo '<p>This where your custom settings go.</p>; } |
Checkout my other WordPress Tutorials by following this LINK
Do you need help with a project? or have a new project in mind that you need help with?
Contact Me