Skip to content

Instantly share code, notes, and snippets.

@mizner
Created August 7, 2016 03:47
Show Gist options
  • Save mizner/aecb75acf2f0caa16335d72f47d3c340 to your computer and use it in GitHub Desktop.
Save mizner/aecb75acf2f0caa16335d72f47d3c340 to your computer and use it in GitHub Desktop.
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment