Creating WordPress Plugin solely for Admin panel with dash menu and submenus

I am attempting to create a WordPress plugin which allows the client to use for help and other resources in a friendly interface. It would be desired if I could have guidance on creating a WordPress plugin with a main dashboard menu and submenus on it which can contain HTML content. As I am a new to WordPress Development, I found it hard to understand the WP Codex.

snapshot

Read More

This is the plugin code:

/** add menu. */
add_action( 'admin_menu', 'my_plugin_menu', 'my_magic_function' );
add_submenu_page( 'my_plugin_menu', 'Page title', 'Sub-menu title', 'manage_options', 'my-submenu-handle', 'my_magic_function');


function my_plugin_menu() {
        add_options_page( 'My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options' );
}

function my_plugin_menu() {
        add_options_page( 'Submenu', 'My Plugin', 'manage_options', 'my-submenu-handle', 'my_plugin_options' );
}

/** html. */
function my_plugin_options() {
        if ( !current_user_can( 'manage_options' ) )  {
                wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
        }
        echo '<div class="wrap">';
        echo '<p>Main page</p>';
        echo '</div>';
}

function my_plugin_options() {
        if ( !current_user_can( 'manage_options' ) )  {
                wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
        }
        echo '<div class="wrap">';
        echo '<p>submenu page</p>';
        echo '</div>';
}

Related posts

1 comment

  1. Here is a simple example to get you started with the right code. This creates a main menu item using add_menu_page then attaches a submenu using add_submenu_page. Both of them call a different function for the output.

    Notice that the add_submenu_page function ties into the parent menu using customteam which is the $menu_slug of add_menu_page.

    add_action( 'admin_menu', 'register_my_custom_menu_page' );
    add_action( 'admin_menu', 'register_my_custom_submenu_page' );
    
    function register_my_custom_menu_page(){
        add_menu_page( 'Team Kit', 'Team Kit', 'manage_options', 'customteam', 'my_custom_menu_page'); 
    }
    
    function register_my_custom_submenu_page() {
        add_submenu_page( 'customteam', 'Team info', 'Team info', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page' ); 
        add_submenu_page( 'customteam', 'Crew Stats', 'Crew Stats', 'manage_options', 'my-custom-submenu-page_2', 'my_custom_submenu_page_2' );
        //add_submenu_page_3 ... and so on
    }
    
    function my_custom_menu_page() {
        echo '<p>Hello, I am Team Kit</p>';
    }
    
    function my_custom_submenu_page() {
        echo '<p>Hello, I am Team Info</p>';
    }
    
    function my_custom_submenu_page_2() {
        echo '<p>Hello, I am Crew Stats</p>';
    }
    

Comments are closed.