submenu

How to add submenu in WordPress custom plugin

This post has been viewed 138 times.

This tutorial will guide you on how to add submenu to your custom WordPress plugin. Many big plugins have this functionality such as Yoast SEO plugin. So if you’re building a plugin you might need to add another page for it.

What you’ll need:

  • A custom WordPress plugin with an Admin Menu.

Step 1: Add an admin page for your custom WordPress plugin.

Before you can start adding a child/submenu to your plugin, first is that you must have a parent menu to connect it from. If you don’t have the parent menu you can read this tutorial how to create an admin page for your WordPress plugin.

Step 2: Create a function.

This will hold the content of the submenu page. In this example, if you click to our submenu this the text in the echo statement will be the output.

Step 3: Call the add_submenu_page function.

This line of code should be included together with the add_menu_page in Step 1.

Complete code:

That’s it, just make sure to activate the plugin. Hover to the main menu of the plugin and the submenu should appear beside it.

Hello, I am a freelance website and mobile application developer. I am also the owner of this website, so if you have any projects for me you can contact me at [email protected] or use the contact page. When I’m not doing some work, I can be found watching Anime/Asian Dramas/American TV Series, playing computer games, and writing tutorials on this website. I run the program repeatedly hoping the error won’t show up next time.