0

I need to add a menu item but it is available as a parent item, I am trying it as follows but in the menu option it is shown as the child of the parent item Settings> My plugins name:

add_action( 'admin_menu', 'my_plugin' );

function my_plugin() {
    add_options_page( 
        'My Options',
        'My plugins name',
        'my_plugin',
        'my-plugin.php',
        'my_plugin_page'
    );
}

I have reviewed this section: https://codex.wordpress.org/Roles_and_Capabilities, but there are many options, I am learning to create plugins for Wordpress.

Thank you very much for your help.

1

That's because it's a helper function for adding pages to the settings section, not the lower level API you expected:

This function is a simple wrapper for a call to add_submenu_page(), passing the received arguments and specifying options-general.php as the $parent_slug argument. This means the new options page will be added as a sub menu to the Settings menu.

https://codex.wordpress.org/Function_Reference/add_options_page

Instead, you want add_menu_page https://developer.wordpress.org/reference/functions/add_menu_page/

  • Many thanks to this option I can add submenu, depending on the parent menu? – Learning and sharing Sep 18 '17 at 23:30
  • yeah, add_submenu_page, look at the related functions on the docs – Tom J Nowell Sep 18 '17 at 23:34

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.