0
0
Wordpressframework~5 mins

Admin menu pages in Wordpress

Choose your learning style9 modes available
Introduction

Admin menu pages let you add new sections to the WordPress dashboard. This helps you organize settings or tools for your site in one place.

You want to add a custom settings page for your plugin.
You need a dashboard area to manage special content types.
You want to create a tool accessible only to site admins.
You want to group related options under a new menu in the admin panel.
Syntax
Wordpress
add_menu_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', string $icon_url = '', int $position = null );

$page_title is the title shown on the page.

$menu_title is the label in the admin menu.

Examples
Adds a new top-level menu called 'My Plugin' with a settings page.
Wordpress
add_menu_page('My Plugin Settings', 'My Plugin', 'manage_options', 'my-plugin', 'my_plugin_page');
Adds a menu with a chart icon for reports.
Wordpress
add_menu_page('Reports', 'Reports', 'manage_options', 'reports', 'reports_page', 'dashicons-chart-bar');
Sample Program

This code creates a new admin menu item called 'My Plugin' with a settings page that shows a heading and a welcome message.

Wordpress
<?php
function my_plugin_page() {
  echo '<div class="wrap"><h1>My Plugin Settings</h1><p>Welcome to the settings page.</p></div>';
}

add_action('admin_menu', function() {
  add_menu_page(
    'My Plugin Settings',
    'My Plugin',
    'manage_options',
    'my-plugin',
    'my_plugin_page',
    'dashicons-admin-generic',
    6
  );
});
OutputSuccess
Important Notes

Use manage_options capability to restrict access to admins.

The $menu_slug must be unique to avoid conflicts.

Icons use Dashicons by default, but you can use custom URLs.

Summary

Admin menu pages add new sections to the WordPress dashboard.

Use add_menu_page inside an admin_menu action.

Set proper capability to control who can see the menu.