Editing the WordPress Admin Menus

The WordPress Admin area is a well-organized hub for all of your website needs. Although it is laid out quite nicely, there are often times when removing, reordering or adding WordPress admin menus and items specific to your needs would be extremely beneficial. In this tutorial I will show you how to do the following:

  • Rename menus
  • Remove menu items you don’t need
  • Register and locate Custom Post Types (CPT) and Advanced Custom Fields (ACF) options pages

Menu Names and Keys

The first thing to understand about the WordPress menu is how the order is controlled. Each menu and submenu is assigned a ‘key’. The top level menu has a key, and each submenu has a key, which acts a child key to the top level menu key. The keys are very important as they control the order of the menu and we will manipulate this number to achieve the desired affect. Here is a list of the default WordPress menu items along with their keys:

 

MenuKeyLink URL
Dashboard2index.php
  – Home0index.php
Separator (first)4separator1
Posts5edit.php
  – All Posts5edit.php
  – Add New10post-new.php
  – Categories15edit-tags.php?taxonomy=category
  – Tags16edit-tags.php?taxonomy=post_tag
Media10upload.php
  – Library5upload.php
  – Add New10media-new
Links15link-manager.php
  – All Links5link-manager.php
  – Add New10link-add.php
  – Link Categories15edit-tags.php?taxonomy=link_category
Pages20edit.php?post_type=page
  – All Pages5edit.php?post_type=page
  – Add New10post-new.php?post_type=page
Comments25edit-comments.php
  – All Comments0edit-comments.php
Separator (Second)59separator2
Appearance60themes.php
  – Themes5themes.php
  – Widgets7widgets.php
  – Menus10nav-menus.php
Plugins65plugins.php
  – Installed Plugins5plugins.php
  – Add New10plugin-install.php
  – Editor15plugin-editor.php
Users70users.php
  – All Users5users.php
  – Add New10user-new.php
  – Your Profile15profile.php
Tools75tools.php
  – Available Tools5tools.php
  – Import10import.php
  – Exports15export.php
Settings80options-general.php
  – General10options-general.php
  – Writing15options-writing.php
  – Reading20options-reading.php
  – Discussion25options-discussion.php
  – Media30options-media.php
  – Privacy35options-privacy.php
  – Permalinks40options-permalink.php
Separator (last)99separator-last

Renaming Menu Items

There are times you may have a site or may be building a site for a client where certain menu names should be changed. Typically, this will be ‘Posts’, as many people use posts for a variety of things such as portfolios, recipes, tutorials, etc.. Here are instructions on renaming menu items on the WordPress admin dashboard.

In order to rename menus you will need to create a function that hooks to the admin_menu action. Inside of that function you will want to use call global $menu to pull in the array of menu items. From there you target the menu item using the ‘key’ as outlined above and alter the name. Here is a basic example showing how to change ‘Posts’ to ‘Portfolio’:

function wd_admin_menu_rename() {
     global $menu; // Global to get menu array
     $menu[5][0] = 'Portfolio'; // Change name of posts to portfolio
}
add_action( 'admin_menu', 'wd_admin_menu_rename' );

Based on the menu keys provided above, you’ll see that ‘Posts’ has a key of 5, so you can see in the function, we target that key specifically and specify the new name of the menu item.

Renaming Sub Menu Items

In a similar fashion you can rename submenus. The only difference is that we need to add an additional global for $submenu to pull in the array of submenu items. Additionally, we need to add a parameter for the link URL (also provided above). Here is an example adding on the the previous one to change ‘All Posts’ to ‘All Portfolio Items’:

function wd_admin_menu_rename() {
     global $menu; // Global to get menu array
     global $submenu; // Global to get submenu array
     $menu[5][0] = 'Portfolio'; // Change name of posts to portfolio
     $submenu['edit.php'][5][0] = 'All Portfolio Items'; // Change name of all posts to all portfolio items
}
add_action( 'admin_menu', 'wd_admin_menu_rename' );

Removing Menu Items

Removing menu items is quite simple. There is a built-in function specifically to accomplish this: remove_menu_page. All you need to do is create a function and use the remove_menu_page action with the link URL specified in the graph at the top of this post and the menu will be removed.

Additionally, removing sub-menus is done in the same exact fashion, but using remove_submenu_page as the action, as well as specifying the parent link URL. Below is an example that remove the ‘Links’ top-level menu and the ‘editor’ sub-menu of the Plugins menu.

function wd_admin_menu_remove() {
     remove_menu_page( 'link-manager.php' );
     remove_submenu_page( 'plugins.php', 'plugin-editor.php' );
}
add_action( 'admin_menu', 'wd_admin_menu_remove' );

Adding New Menu Items

One other important part of building with WordPress is the use of Custom Post Types and options pages. Below are a few techniques for implementation of these items.

When setting up a custom post type there is a parameter called menu_position. This is not a required parameter when registering a custom post type, but using it will allow you to control exactly where your CPT shows up in the menu. Here is the code used to register the custom Projects post type I use on this site:

//* Register Projects Post Type
add_action( 'init', 'wd_projects_cpt' );
function wd_projects_cpt() {
	$labels = array(
		'name'               => _x( 'Projects', 'post type general name' ),
		'singular_name'      => _x( 'Project', 'post type singular name' ),
		'menu_name'          => _x( 'Projects', 'admin menu' ),
		'name_admin_bar'     => _x( 'Project', 'add new on admin bar' ),
		'add_new'            => _x( 'Add New', 'Project' ),
		'add_new_item'       => __( 'Add New Project' ),
		'new_item'           => __( 'New Project' ),
		'edit_item'          => __( 'Edit Project' ),
		'view_item'          => __( 'View Project' ),
		'all_items'          => __( 'All Projects' ),
		'search_items'       => __( 'Search Projects' ),
		'parent_item_colon'  => __( 'Parent Projects:' ),
		'not_found'          => __( 'No Projects found.' ),
		'not_found_in_trash' => __( 'No Projects found in Trash.' )
	);

	$args = array(
		'labels'             => $labels,
		'description'        => __( 'Whiteley Designs Project Showcase.' ),
		'public'             => true,
		'publicly_queryable' => true,
		'show_ui'            => true,
		'show_in_menu'       => true,
		'query_var'          => true,
		'rewrite'            => array( 'slug' => 'project' ),
		'capability_type'    => 'post',
		'has_archive'        => true,
		'hierarchical'       => false,
		'menu_position'      => 11,
		'menu_icon'          => 'dashicons-portfolio',
		'supports'           => array( 'title', 'editor', 'author', 'thumbnail' )
	);

	register_post_type( 'project', $args );
}

You’ll see in the $args array there is a menu_position of 11. This puts the Projects menu directly under the ‘Media’, which has a key of 10. Simply choose a number that relates to the key provided at the top of this post and your CPT menu link will show exactly where you want it to. I also suggest specifying a menu_icon so you have a nice icon for your CPT. You can choose from any of the WordPress dashicons (https://developer.wordpress.org/resource/dashicons/).

Another staple of every project I work on is the implementation of Advanced Custom Fields. Using the PRO version I am able to implement options pages that make site management for clients very simple. Below is a technique for registering an options page and specifying a menu location.

//* ACF -- Add options page
if( function_exists('acf_add_options_page') ) {
	acf_add_options_page(array(
		'page_title' 	=> 'Theme Settings',
		'menu_title'	=> 'Theme Settings',
		'menu_slug' 	=> 'wd-theme-settings',
		'capability'	=> 'edit_posts',
		'position'      => '76',
		'icon_url'      => 'dashicons-list-view',
		'redirect'	=> false
	));
}

This is the function used to register an options page for Advanced Custom Fields as specified in their documentation. The ‘position’ parameter is the key to locating your options page where you want it. In this example we use 76 which places the link between the ‘Tools’ and the ‘Settings’ menu.

Again, I also suggest specifying the ‘icon_url’ parameter, which acts the same as the menu_icon parameter in the Custom Post Type registration discussed earlier.


Customizing the WordPress menu for clients is a really nice touch that can really give your finished product a polished look. You can make site management for your clients simple by prioritizing the important links, removing un-needed ones, and if you want to take it a step further, altering the menus based on user role. We’ll save that post for another time.

If you have any questions, post in the comments section!

Comments

  1. Hey Matt!

    If I want to change the icon? The way I’m doing is working fine, but I think the code could be cleaner.

    I have that function of yours to rename the default WordPress Post Type to Portfolio, and then I add a new menu item with `add_menu_page()`, so I can customise the icon.

    Do you know a simple way to work that out? I need this template to be very, very clear, otherwise the client will not understand the difference between “Post” and “Portfolio” -_-‘ haha!

    Thanks! 😀

    • Hey Filipe,

      You have a few options. If you want to change the icon of the default WordPress Posts (which you’ve renamed to Portfolio) the simplest way is CSS. Something like this would get it done:

      body .dashicons-admin-post:before {
      content: “\f109”;
      }

      You’d need to replace the “f109” with the correct reference to the icon you want to show. You can find the references in the codex:

      https://developer.wordpress.org/resource/dashicons/

      You’d need to add this CSS using a function so it applies to the admin area. Here is a good tutorial for that from Chris at CSS-Tricks:

      https://css-tricks.com/snippets/wordpress/apply-custom-css-to-admin-area/

      The other option would be to create a custom post type for your Portfolio posts instead of changing the name of the default Posts. Doing it that way you could define the icon using the menu_icon setting in the args of the custom post type.

      Hope that helps!

      Cheers,

      Matt

Leave a Reply

Your email address will not be published. Required fields are marked *