Create WordPress admin menu for your plugin

If you create a WordPress plugin, you want to allow users to change settings from the WordPress dashboard. Adding a WordPress admin menu lets you allow users to customize your plugin to fit their needs.

At this point in your WordPress plugin development, you should already have started to create the WordPress plugin function to control what your plugin does.

Create WordPress admin menu link

To make your WordPress plugin settings easily accessible, it’s best to create an admin menu in the dashboard. This menu should have fields where users can customize your plugin to fit their exact needs.

Use the WordPress function add_action along with admin_menu to let WordPress know we’re building an admin menu. Then pass the function name of your menu extra_post_info_menu that sets up your menu item.

add_action( 'admin_menu', 'extra_post_info_menu' );  function extra_post_info_menu(){    $page_title = 'WordPress Extra Post Info';   $menu_title = 'Extra Post Info';   $capability = 'manage_options';   $menu_slug  = 'extra-post-info';   $function   = 'extra_post_info_page';   $icon_url   = 'dashicons-media-code';   $position   = 4;    add_menu_page( $page_title,                  $menu_title,                   $capability,                   $menu_slug,                   $function,                   $icon_url,                   $position ); } 
Variable name Description
$page_title The title shown in the web-browser when viewing your plugin page
$menu_title The title for the menu button shown in the WordPress dashboard
$capability manage_options allows only Super Admin and Administrator to view plugin
$menu_slug URL to access plugin such as: /wp-admin/admin.php?page=extra-post-info
$function The function that contains the code for what to actually display on your plugin page
$icon_url Icon used in dashboard. You can use WordPress dash icons, or direct images like: $icon_url = plugins_url( ‘extra-post-info/icon.png’ );
$position Icon position in dashboard

WordPress position numbers:

2 Dashboard  4 Separator  5 Posts  10 Media  15 Links  20 Pages  25 Comments  59 Separator  60 Appearance  65 Plugins  70 Users  75 Tools  80 Settings  99 Separator

Function name Description
add_menu_page The WordPress function that hooks in and builds our plugin menu in the dashboard

Blank plugin page accessed from dashboard menu

At this point you should be able to see your WordPress plugin menu in the dashboard. If you click on it, you’re just going to get a blank page as you haven’t told WordPress what to put here yet.

Create WordPress plugin page

Once your admin menu is made, the next thing you’ll want to do is create a WordPress plugin page.

Thoughts on “Create WordPress admin menu for your plugin

    • Hello!

      The code should be added to the custom PHP script in your plugin’s directory. That file should be created into the wp-content/plugins/plugin-name/ directory. If your website’s document root directory is the default public_html directory, then the location of the file would be similar to:


      I recommend reviewing our guide on how to create a WordPress plugin script, for more details. I hope this helps!

      Carlos D

Leave a Reply