mizner
8/7/2016 - 3:47 AM

Wordpress add dashboard menu, page, and subpage

Wordpress add dashboard menu, page, and subpage

<?php 
add_action( "admin_menu", "example_admin_menus" );

function example_admin_menus() {
	add_menu_page(
		"Plugin Page", // $page_title
		"Plugin Page", // $menu_title
		"manage_options", // $capability
		"plugin_page", // $menu_slug
		"plugin_render_page", // $function
		"dashicons-location", // $icon_url
		1 // $position
	);


	add_submenu_page(
		"plugin_page",       // parent slug
		"Sub Menu",             // page title
		"Sub Menu",             // menu title
		"manage_options",           // capability
		"plugin_subpage",      // slug
		"plugin_render_subpage" // callback
	);


	// REMOVE THE SUBMENU CREATED BY add_menu_page
	global $submenu;
	unset( $submenu["plugin_page"][0] );

}

function plugin_render_page() {
	?>
	<div class="wrap">
		<h2>Plugin Page</h2>
	</div>
	<?php
}

function plugin_render_subpage() {
	?>
	<div class="wrap">
		<h2>Plugin SubPage</h2>
	</div>
	<?php
}