Does your WordPress admin menu feel cluttered? Are there items your clients never use that just confuse them? Or maybe you want to add a quick link to your favorite tool or a custom post type?
While plugins can do this with a click, there's a powerful way to customize it yourself by adding a few lines of code. It’s not as scary as it sounds! By editing your theme's functions.php
file, you can rename, rearrange, add, and even restrict menu items.
Let's dive in and learn how to tailor the WordPress admin menu to your exact needs.
Safety First!
Before we start, a word of caution: we'll be adding code to your theme's functions.php
file. A small mistake can break your site.
- Always use a Child Theme: This prevents your changes from being erased when your theme updates.
- Backup Your Site: Always, always backup your site before making any code changes.
Ready? Let's get started.
1. Introducing functions.php
All our code will go into your child theme's functions.php
file. You can find this by going to Appearance > Theme File Editor in your WordPress dashboard. Select your child theme from the dropdown on the right.
Alternatively, you can access it via FTP by navigating to /wp-content/themes/your-child-theme-name/functions.php
.
We'll be using a powerful WordPress hook called admin_menu
. This hook allows us to make changes right before the admin menu is displayed.
2. How to Change Existing Menu Items (Name, Icon, URL)
Let's say you want to change the name of "Posts" to "Articles" and give it a different icon.
Here's the code you would use:
php
function wpadminify_customize_admin_menu() {
global $menu;
// Change "Posts" to "Articles"
$menu[5][0] = 'Articles'; // The number 5 is the position of the "Posts" menu
// Change the icon for "Articles" (using a Dashicon)
$menu[5][6] = 'dashicons-book-alt'; // URL to a custom icon also works
}
add_action( 'admin_menu', 'wpadminify_customize_admin_menu' );
How it works:
global $menu; makes the global menu array available for us to edit.
The number 5 refers to the position of the "Posts" menu item in the admin menu.
[0] is the array key that holds the menu name.
[6] is the array key that holds the icon URL. WordPress has a built-in icon font called Dashicons.
3. How to Add a Brand New Custom Menu Item
Want to add a link to your portfolio or a handy external tool like Google Analytics right inside the admin menu? You can do that too!
We'll use the add_menu_page() function. Read the comments inside the code and you will get a proper idea. If still face problem then just comment and I will respond.
function wpadminify_add_custom_menu_link() {
add_menu_page(
'Google Analytics', // Page title (title of the browser tab)
'Analytics', // Text to show in the menu
'manage_options', // Capability required to see this link (e.g., 'manage_options' for admins)
'https://analytics.google.com/', // The URL this menu links to
'', // Function that outputs the page content (empty since we're linking externally)
'dashicons-chart-bar', // The icon for the menu (a Dashicon)
2 // Position in the menu (2 puts it right under Dashboard)
);
}
add_action( 'admin_menu', 'wpadminify_add_custom_menu_link' );
4. How to Restrict a Menu for a Specific User or Role
This is where the real power comes in. Let's say you have a "Client" role and you want to hide the "Tools" menu from everyone who is not an Administrator.
We can use current_user_can()
to check the user's role or capabilities.
Example 1: Hide "Tools" for everyone except Admins
function wpadminify_remove_menus() {
// Check if the current user is NOT an administrator
if ( !current_user_can( 'manage_options' ) ) {
remove_menu_page( 'tools.php' ); // Removes the Tools menu
}
}
add_action( 'admin_menu', 'wpadminify_remove_menus' );
Example 2: Hide "Posts" for a specific user named "client_user"
function wpadminify_remove_menus_for_user() {
// Get the current user's login name
$current_user = wp_get_current_user();
// Check if the username is 'client_user'
if ( $current_user->user_login == 'client_user' ) {
remove_menu_page( 'edit.php' ); // Removes the Posts menu
}
}
add_action( 'admin_menu', 'wpadminify_remove_menus_for_user' );
Let's add all code together for a Complete Example.
Here’s how you could combine all these techniques into one neat code snippet for your functions.php file.
/**
* WPAdminify Custom Admin Menu Setup
*/
function wpadminify_custom_admin_menu_setup() {
// 1. Rename Posts to Articles
global $menu;
$menu[5][0] = 'Articles';
// 2. Add a Custom Analytics Link
add_menu_page(
'Google Analytics',
'Analytics',
'manage_options',
'https://analytics.google.com/',
'',
'dashicons-chart-bar',
2
);
// 3. Remove Tools menu for non-Admins
if ( !current_user_can( 'manage_options' ) ) {
remove_menu_page( 'tools.php' );
}
}
add_action( 'admin_menu', 'wpadminify_custom_admin_menu_setup' );
[Note: You maybe noticed I have named WPAdminify in the functions, it's because I tried to make it unique with my plugin name so that it doesn't conflict with your dashboard.]
Conclusion
And there you have it! You’ve just learned how to professionally customize the WordPress admin menu without relying on a single plugin. You can now rename items, add helpful external links, and hide menu items from users who shouldn't see them.
This approach is lightweight, gives you full control, and is a great skill for any WordPress developer or savvy site owner.
Remember to always test your code on a staging site first and have fun creating a cleaner, more efficient WordPress dashboard for yourself and your clients.
Top comments (0)