Skip to content

Instantly share code, notes, and snippets.

@doubleedesign
Last active December 16, 2023 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doubleedesign/085ce2bef8d3c6ab2cfd3440e9cc2315 to your computer and use it in GitHub Desktop.
Save doubleedesign/085ce2bef8d3c6ab2cfd3440e9cc2315 to your computer and use it in GitHub Desktop.
Rename a WordPress admin menu item without knowing its index (because they can change!)
<?php
// Note: it's not mandatory to put this in a class, it's just how I write my plugins
class Doublee_Admin_UI {
public function __construct() {
add_action('admin_menu', array($this, 'rename_menu_items'));
// ...other function calls
}
/**
* Rename some menu items
* @return void
*/
function rename_menu_items(): void {
global $menu;
foreach($menu as $index => $item) {
if($item[0] === 'Users') {
$menu[$index][0] = 'User Accounts';
break; // If you only have one change, stop here so there's no unnecessary iterations
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment