0

I need to add a dropdown menu like the entries in Wordpress, I am adding this code I have managed to add the parent item to the left side menu, but I need the user to do a Mousehover appear more menu options, I am learning to create plugins and I have this Doubt, I appreciate your support.

Example:

Example

function my_plugins(){
    add_menu_page( 
        'My Plugin',
        'My Plugin',
        'manage_options',
        'visitor-counter-by-funcion',
        'my_custom_menu_page',
        'dashicons-chart-bar'
    ); 
}
add_action( 'admin_menu', 'my_plugins' );

/**
 * Display a custom menu page
 */
function my_custom_menu_page(){
    esc_html_e( 'Admin Page Test', 'textdomain' );  
}
1

What you are searching for its a submenu page. Try with this:

add_submenu_page( 'my-top-level-slug', 
                  'My Custom Submenu Page', 
                  'My Custom Submenu Page',
                  'manage_options', 
                  'my-secondary-slug'
);

you can find more info here

An example with your code:

function my_plugins() {
    add_menu_page(
            'My Plugin', 
            'My Plugin', 
            'manage_options', 
            'visitor-counter-by-funcion', //THIS IS THE SLUG YOU NEED TO USE IN YOUR SUBMENU ITEMS
            'my_custom_menu_page', 
            'dashicons-chart-bar'
    );
    add_submenu_page(
            'visitor-counter-by-funcion', //THIS IS THE SLUG OF YOUR PARENT MENU PAGE
            'My Custom Submenu Page', 
            'My Custom Submenu Page', 
            'manage_options', 
            'my-secondary-slug', 
            'my_custom_sub_menu_page'
    );
}

add_action('admin_menu', 'my_plugins');

/**
 * Display a custom menu page
 */
function my_custom_menu_page() {
    esc_html_e('Admin Page Test', 'textdomain');
}

/**
 * Display callback for the submenu page.
 */
function my_custom_sub_menu_page() {
    ?>
    <div class="wrap">
        <h1><?php _e('My Custom Submenu Page', 'textdomain'); ?></h1>
        <p><?php _e('My Custom Submenu Page', 'textdomain'); ?></p>
    </div>
    <?php
}

its looking like this:

enter image description here

  • Hello David, you can give me an example joining your code with which I have placed in this post, I am new to this – Learning and sharing Sep 19 '17 at 17:58
  • sure, answer updated. – David Lee Sep 19 '17 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.