Quite often I run into instances where I need to change the display name of a top level menu item in the WordPress wp-admin backend. Sometimes this is to change Posts to something more relevant to the client, such as Skydive Log, or I simply do not like how a plugin named its menu and want to make it look better for the client. There is a global variable called $menu that allows me to do this in an easy manner. Use the hook ‘admin_menu’ to tap into the menu creation, alter the $menu variable, and you have yourself a freshly renamed menu item.
Here is some code to help you get this running:
function rename_top_level_menus() {
_rename_top_level_menu( 'Tools', 'ThisBeDaToolz' );
}
In this function you will put all your calls to the function doing the actual renaming. The first parameter is the original name, and the second is the new name to display.
Next up you need to setup the hook into the ‘admin_menu’ action
add_action( 'admin_menu', 'rename_top_level_menus' , 1000 );
And finally this is the code that makes the magic happen
function _rename_top_level_menu( $original, $new ) {
global $menu;
foreach( $menu AS $k => $v ) {
if( $original == $v[0] ) {
$menu[$k][0] = $new;
}
}
}
You can drop this code into a functions.php file, or into a plugin and you can start using it right away.
All together now
Here is the entire code for this article in one swoop
function rename_top_level_menus() {
_rename_top_level_menu( 'Tools', 'ThisBeDaToolz' );
}
add_action( 'admin_menu', 'rename_top_level_menus' , 1000 );
function _rename_top_level_menu( $original, $new ) {
global $menu;
foreach( $menu AS $k => $v ) {
if( $original == $v[0] ) {
$menu[$k][0] = $new;
}
}
}