[WordPress] Plugin’s Menu

To create a menu for a custom plugin, you can use the function add_menu_page. Here is a sample:


add_menu_page('Title of the page', 'The text to appear in menu', 'create_users', 'a-unique-slug-to-avoid-conflicts', 'function-that-renders-the-page-to-appear');

This will create a main menu item. To create a sub menu item under the one mentioned above, we can use the add_submenu_page. Here is a sample code:


add_submenu_page('the-slug-you-used-above-in-the-main-menu-item', 'Page title to appear', 'The text to appear in menu', 'create_users', 'another-different-unique-slug', 'function-that-renders-the-page-to-appear' );

The ‘create_users’ is the permission required for this menu item/page to be visible/accessible.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>