ZaZaKi, a web developer Between Manchester UK & Rotterdam NL. © 2015-2025.

WP Plugin Admin Main and Sub Menus

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/*Plugin Name: MyPlugin*/
// exit if file is called directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
 
function example_admin_menus() {
add_menu_page(
"Main & Sub Menu", // $page_title
"Main & Sub Menu", // $menu_title
"manage_options", // $capability
"main_and_sub_menu", // $menu_slug
"main_menu", // $function
"dashicons-menu", // $icon_url
null // $position
);
add_submenu_page(
"main_and_sub_menu", // parent slug
"Sub Menu", // page title
"Sub Menu", // menu title
"manage_options", // capability
"plugin_subpage", // slug
"sub_menu" // callback
);
 
}
add_action( "admin_menu", "example_admin_menus" );
 
function main_menu() {
?>
<div class="wrap">
<h2>Main & Sub Menu</h2>
<h3>Main Menu</h3>
</div>
<?php
}
 
function sub_menu() {
?>
<div class="wrap">
<h2>Main & Sub Menu</h2>
<h3>Sub Menu</h3>
</div>
<?php
}