Last active
December 16, 2023 06:49
-
-
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!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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