Building a custom WordPress admin menu with submenus and capabilities
WordPress gives administrators a familiar dashboard, but many projects need a more focused back-office experience. A membership site may require a customer management screen, a WooCommerce extension may need order tools, and a publishing workflow may benefit from a dedicated editorial menu. A custom admin menu can bring these features together without forcing users to navigate unrelated settings.
The important part is not simply adding a label to the left-hand dashboard navigation. A reliable implementation must register menu pages, connect submenu items, define capability checks, load assets only where they are needed, and prevent unauthorised access if someone visits a screen URL directly. These details matter for both security and maintainability.
This guide uses WordPress hooks, PHP callbacks, custom capabilities, and a small amount of admin CSS and JavaScript. The examples suit a plugin, which is generally safer than placing application functionality in a theme. They can be adapted for sites managed in Sydney, Melbourne, Brisbane, or elsewhere in Australia, including stores using local payment, shipping, and tax workflows.
Plan the menu around permissions
Before writing PHP, decide which users need to see each screen and which actions they may perform. WordPress roles such as administrator, editor, author, and shop_manager contain capabilities, but checking a role name directly is brittle. A capability expresses the required permission and continues to work if roles are renamed or customised.
For example, a private operations area might use manage_acme_orders, while a reporting page could use view_acme_reports. The first capability could be limited to senior staff, while the second might be available to a bookkeeper or store manager. This is more precise than granting every user with edit_posts access to sensitive customer information.
A custom menu can contain one parent page and several children. The parent callback displays an overview, and submenu callbacks display focused tools:
add_action( 'admin_menu', 'acme_register_admin_menu' );
function acme_register_admin_menu() {
add_menu_page(
'Acme Operations',
'Acme Operations',
'manage_acme_orders',
'acme-operations',
'acme_render_overview',
'dashicons-clipboard',
26
);
add_submenu_page(
'acme-operations',
'Order Queue',
'Order Queue',
'manage_acme_orders',
'acme-order-queue',
'acme_render_order_queue'
);
add_submenu_page(
'acme-operations',
'Reports',
'Reports',
'view_acme_reports',
'acme-reports',
'acme_render_reports'
);
}
The fifth argument is the capability required to view a page. WordPress hides a menu item when the current user lacks that capability, but your callback should still verify access. This protects the screen if its URL is copied or requested directly.
Register the parent and child screens
The add_menu_page() function creates a top-level item. Its parameters define the browser title, visible menu label, required capability, slug, rendering callback, icon, and menu position. A position around 26 usually places the item below Comments, although positions can vary when plugins add their own menus.
The first parameter passed to add_submenu_page() must match the parent slug. The child page then receives its own title, label, capability, slug, and callback. A parent page automatically receives a submenu item that points to itself, which is why the example may show “Acme Operations” twice in the expanded navigation. That behaviour is normal, but you can replace the first child label if a different workflow is clearer.
For a single-purpose tool, a submenu-only page can be attached to an existing WordPress menu:
add_action( 'admin_menu', 'acme_add_tools_page' );
function acme_add_tools_page() {
add_submenu_page(
'tools.php',
'Import Audit',
'Import Audit',
'manage_options',
'acme-import-audit',
'acme_render_import_audit'
);
}
Common parent slugs include options-general.php for Settings, tools.php for Tools, and woocommerce for WooCommerce installations. Do not assume that a third-party parent always exists. If your plugin depends on WooCommerce, check that the plugin is active before registering a WooCommerce submenu, or provide a fallback location.
Each callback should produce valid, accessible markup. It should also perform a capability check before output:
function acme_render_reports() {
if ( ! current_user_can( 'view_acme_reports' ) ) {
wp_die(
esc_html__( 'You do not have permission to view this page.', 'acme' ),
403
);
}
echo '<div class="wrap">';
echo '<h1>' . esc_html__( 'Reports', 'acme' ) . '</h1>';
echo '<p>' . esc_html__( 'Review operational activity and sales summaries.', 'acme' ) . '</p>';
echo '</div>';
}
Using translation functions gives the plugin a path to localisation. Escaping output with esc_html(), esc_attr(), or wp_kses_post() should become routine, especially when a value comes from a database, request parameter, or user profile.
Add capabilities safely during activation
Custom capabilities do not appear automatically. A plugin should add them to the relevant roles during activation and remove them during uninstall only if that is appropriate for the project. Removing permissions on deactivation can lock administrators out of a screen when the plugin is temporarily disabled and re-enabled.
register_activation_hook( __FILE__, 'acme_add_capabilities' );
function acme_add_capabilities() {
$roles = array( 'administrator', 'shop_manager' );
foreach ( $roles as $role_name ) {
$role = get_role( $role_name );
if ( $role ) {
$role->add_cap( 'manage_acme_orders' );
$role->add_cap( 'view_acme_reports' );
}
}
}
The shop_manager role is particularly useful for WooCommerce businesses, while the administrator role provides a fallback for site owners. On an Australian online shop, you may want warehouse staff in Melbourne to access fulfilment screens without exposing configuration pages or customer exports. Assign only the capabilities required for each job.
A production plugin may need a migration routine rather than relying on activation alone. Existing installations will not run the activation hook when a new capability is added in a plugin update. Store a capability version in an option and run the migration when the plugin loads, or use an upgrade routine tied to the plugin version.
Avoid using manage_options for every page simply because it is convenient. It grants access to broad site settings and can exclude legitimate operational users. Conversely, avoid using read for pages that expose private records. A user who can access a menu screen may be able to view names, addresses, order values, or internal notes.
Capability checks must also protect actions inside a screen. If a report page includes a “Delete log” button, the deletion handler needs its own current_user_can() check. Menu visibility is a navigation feature, not an authorisation system.
Protect forms, requests, and data
Admin pages frequently include forms for saving settings, filtering records, importing data, or triggering background tasks. Use a nonce to confirm that the request came from an authorised WordPress session, then sanitise and validate every submitted value.
function acme_render_settings() {
if ( ! current_user_can( 'manage_acme_orders' ) ) {
wp_die( esc_html__( 'Access denied.', 'acme' ), 403 );
}
if (
isset( $_POST['acme_save_settings'] ) &&
check_admin_referer( 'acme_save_settings_action', 'acme_settings_nonce' )
) {
$email = isset( $_POST['notification_email'] )
? sanitize_email( wp_unslash( $_POST['notification_email'] ) )
: '';
if ( is_email( $email ) ) {
update_option( 'acme_notification_email', $email );
add_settings_error(
'acme_messages',
'acme_saved',
'Settings saved.',
'updated'
);
}
}
settings_errors( 'acme_messages' );
?>
<div class="wrap">
<h1><?php esc_html_e( 'Acme settings', 'acme' ); ?></h1>
<form method="post">
<?php wp_nonce_field( 'acme_save_settings_action', 'acme_settings_nonce' ); ?>
<input
type="email"
name="notification_email"
value="<?php echo esc_attr( get_option( 'acme_notification_email', '' ) ); ?>"
/>
<p>
<button type="submit" name="acme_save_settings" class="button button-primary">
<?php esc_html_e( 'Save settings', 'acme' ); ?>
</button>
</p>
</form>
</div>
<?php
}
check_admin_referer() protects the form against cross-site request forgery, but it does not replace a capability check. Use both. For destructive links, pass a nonce through wp_nonce_url() and handle the request with a clear confirmation flow. Never delete records merely because a query parameter is present.
Redirect after a successful form submission to prevent duplicate writes when a user refreshes the page. wp_safe_redirect() followed by exit; is suitable for this pattern. For settings-heavy pages, the WordPress Settings API can handle registration, field rendering, sanitisation, and storage more consistently than a hand-built form.
When a screen uses AJAX or the REST API, secure the endpoint independently. Check the user’s capability in the AJAX callback or REST permission_callback, verify nonces where applicable, and validate record IDs before querying. A hidden menu item provides no protection for an exposed endpoint.
Load assets only on your screens
Admin CSS and JavaScript should be enqueued conditionally. Loading a custom stylesheet across every dashboard page can cause conflicts with WooCommerce, page builders, or client-specific admin customisations. The admin_enqueue_scripts hook provides the current screen hook suffix.
add_action( 'admin_enqueue_scripts', 'acme_enqueue_admin_assets' );
function acme_enqueue_admin_assets( $hook_suffix ) {
$allowed_hooks = array(
'toplevel_page_acme-operations',
'acme-operations_page_acme-order-queue',
'acme-operations_page_acme-reports',
);
if ( ! in_array( $hook_suffix, $allowed_hooks, true ) ) {
return;
}
wp_enqueue_style(
'acme-admin',
plugin_dir_url( __FILE__ ) . 'assets/admin.css',
array(),
'1.0.0'
);
wp_enqueue_script(
'acme-admin',
plugin_dir_url( __FILE__ ) . 'assets/admin.js',
array( 'jquery' ),
'1.0.0',
true
);
}
The hook suffix is generated from the menu slug, so confirm its value while developing rather than guessing. get_current_screen() can also be useful when a plugin has several related pages. Keep dependencies explicit and use a version based on the plugin version or file modification time during development.
For a site with a large product catalogue, an admin page may need filters, pagination, and asynchronous search. A small JavaScript enhancement is preferable to loading a full front-end framework for one table. Keep keyboard navigation, focus states, labels, and readable contrast in place; dashboard tools are often used for long shifts and on varied monitor sizes.
Test the menu with every role that will use it. Check the administrator dashboard, a shop manager account, an editor, and a logged-out request. Test on a staging copy before deployment, especially when the menu interacts with WooCommerce orders, customer data, or stock records. Teams managing stores across Brisbane and Perth may also depend on time-sensitive fulfilment actions, so avoid unnecessary network requests in the admin.
Test the finished dashboard
A custom admin menu should be tested as a complete permission boundary, not just as a visual feature. Confirm that the parent page appears for permitted users, restricted submenus remain hidden, direct URLs return an access error, and form submissions fail safely without a valid nonce.
Automated browser testing can cover login, menu visibility, page navigation, form validation, and redirects. A headless browser suite such as browser test tools can be useful when the same workflow must be checked against multiple WordPress versions or plugin combinations. This is valuable for agencies supporting clients in different Australian states, where each installation may have different roles and integrations.
PHP-level tests should cover capability assignment, sanitisation, and business rules separately from browser tests. Static analysis can identify undefined functions, incorrect hook signatures, and unsafe output. WordPress coding standards also catch issues such as inconsistent escaping and weak comparisons.
When troubleshooting a page that does not appear, inspect the user capability first, then verify that the admin_menu hook is running and that the parent slug is correct. A fatal error in a callback may occur only when the page is opened, while a missing activation migration can leave the menu visible but inaccessible. Practical WordPress debugging references and community solutions, including WordPress QA answers, can help compare symptoms with known hook, role, and submenu issues.
Keep the implementation modular: one function for registration, one for capabilities, separate render callbacks, and dedicated handlers for form or AJAX actions. This makes future changes safer, whether the menu later gains inventory reconciliation for a Sydney retailer, GST reporting for an Australian WooCommerce store, or a restricted export page for authorised staff.