Anatomy Of A WordPress Plugin: Adding Admin Submenus For Options Pages

WordPressI have not yet written a plugin for WordPress that is complex enough to require the settings to be broken down over multiple pages in the Admin area, but this is something that is possible to do fairly easily.

In the last post we covered adding a link on the menu using the add_options_page function.

This function works for a single options page, but this function doesn’t work for submenus.

Instead we need to use add_menu_page to add the top level menu and add_submenu_page.

As with add_options_page, these functions are called using the add_action function with the admin_menu hook to call a custom function.

The code below shows the two functions being called for a mocked up example:

add_action("admin_menu", "azc_create_menus");

function azc_create_menus() {
    add_menu_page( "azurecurve Menu"
			, "azurecurve Menu"
			, 0
			, "azurecurve-menu-slug"
			, "azurecurveMenuPageFunction"
			, plugins_url( '/images/favicon.ico', __FILE__ ) );
	add_submenu_page( "azurecurve-menu-slug"
			, "azurecurve Submenu"
			, "azurecurve Submenu"
			, 0
			, "azurecurve-submenu-slug"
			, "azurecurveSubmenuPageFunction" );

Continue reading