Customizing the WordPress Admin: Custom Admin Menus

In the first two parts of this series, I showed you how to customise the WordPress login screen and the dashboard. In this third part I'll show you how to customize the admin menus in WordPress.

In this tutorial you'll learn how to:

  1. Rename a menu item (in this case, 'Posts')
  2. Remove a menu item (in this case, 'Comments')
  3. Reorder your menu so that the items you use more frequently are higher up

I'm going to create a plugin to do this - if you've already created a plugin after following Parts 1 and 2 of this series you may prefer to add the code from this tutorial to that plugin, giving you one plugin with all of your admin customization.


What You Will Need to Complete This Tutorial

To complete this tutorial you will need:

  • A WordPress installation
  • Access to your site's plugins folder to add your plugin
  • A text editor to create your plugin

Setting Up the Plugin

At the beginning of my plugin, I'm adding the following lines:


1. Renaming a Menu Item

Most of the sites I build in WordPress aren't blogs - they're generally client sites which if they use posts, will use them for news rather than blog posts. So I'm going to rename 'Posts' in the admin menu to 'News'. You can rename any WordPress content type to whatever you want, for example:

  • posts could become news, articles or updates
  • media could become images, attachments or uploads

To rename posts, add the following code to your plugin:

This code references the $menu and $submenu global variables - the numbers in square brackets tell WordPress which menu items I'm referring to, as each menu item has its own number which corresponds with its order in the menu. I attach my function to rename posts to the admin_menu hook, which is the action hook I'll be using throughout this tutorial.

This changes the admin menu as shown in the screenshot:

customizing-the-wordpress-admin-part3-posts-renamed

Note: the Dashboard shown in the screenshot has been customized so doesn't look like the standard dashboard. See Part 2 of this series for more details.

As you can see, where the 'Posts' menu normally is, it reads 'News'. This gives you access to posts in the same way as before but with a different label. The post type has not changed.

The next step is to rename the submenu items for posts, and any other use of the term 'post' in the admin screens.

In your plugin, add the following:

Now not only only the top level menu item has changed, but all references to posts, as shown in the screenshot:

customizing-the-wordpress-admin-part3-posts-renamed-submenus

The submenu has new labels as does the 'Add News Item' link and the editing screen title.


2. Removing Menu Items

The admin menu is closer to reflecting the structure of my client sites, now that posts are referred to as news items. But I can simplify things further by removing any menu items I don't need.

In most of the client sites I build, comments are turned off. So I can remove them from the admin menu to avoid confusing clients.

In your plugin, add the following:

This uses the remove_menu_page hook with the slug for the comments editing page, which is edit-comments.php.

Note: I've enclosed the function in a check for the manage_options capability, so that the Comments menu item will not be hidden to administrators, just in case!

As you can see in the screenshot, the Comments menu item has now been removed.

customizing-the-wordpress-admin-part3-remove-menu-item

3. Reordering Menu Items

The final customization I'm going to make is to reorder the admin menu, so that items my clients will use more frequently are higher up. In this case, I'm going to move the Pages menu item above media.

You do this using two filters:

  • custom_menu_order, which activates the menu_order filter and must have __return_true as its value.
  • menu_order, to which you attach your function defining the new menu order.

In your plugin, add the following:

This will reorder the menu in the order specified in the array, so that Media appears after Pages. You now have a simple customized admin menu.


Summary

Customizing the WordPress admin menu can make the process of managing a site easier and quicker for yourself and your clients, by giving menu items more appropriate labels, removing unwanted items and ensuring the menu is in the most useful order. You can take this further by moving any custom post types up and down in your menu, renaming media perhaps, and more.

Tags:

Comments

Related Articles