add_menu_page

Home » Functions » add_menu_page

add_menu_page is a WordPress function that enables developers to add a new top-level menu item to the WordPress admin menu.

This function is used to create a new menu item in the WordPress admin panel, which can be added to the main navigation menu or the submenu. When a user clicks on the menu item, they are taken to a custom page or URL defined by the developer. This function can be used to add a custom menu item to the WordPress admin panel for a plugin or theme.

The function takes several parameters, including the page title, the menu title, the required capability to access the menu item, the slug, the function to call when the page is displayed, and the icon to display in the menu item. The developer can also specify where the menu item appears in the menu hierarchy, and if it should be displayed to specific users.

Here is an example usage of the add_menu_page function:

add_action('admin_menu', 'my_plugin_menu');

function my_plugin_menu() {
   add_menu_page(
      'My Plugin Settings', // page title
      'My Plugin', // menu title
      'manage_options', // capability
      'my-plugin-settings', // slug
      'my_plugin_settings_page', // callback function
      'dashicons-admin-plugins', // icon URL
      100 // menu position
   );
}

function my_plugin_settings_page() {
   // function to display settings page
}

In this example, the add_menu_page function is used to create a new top-level menu item called "My Plugin" with the title "My Plugin Settings". The user must have the "manage_options" capability to access the menu item. The slug is "my-plugin-settings" and the function "my_plugin_settings_page" is called when the page is displayed. The icon URL is set to "dashicons-admin-plugins", and the menu item is positioned at 100 in the menu hierarchy.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.