0

I can rename wp-admin menu items But How Can I active it for all users except Super Admin ?

add_filter('gettext', 'rename_admin_menu_items');
add_filter('ngettext', 'rename_admin_menu_items');
function rename_admin_menu_items( $menu ) {
$menu = str_ireplace( 'Dashboard', 'Home', $menu );
return $menu;
}
4
  • Which hook are you using?
    – kaiser
    Aug 14, 2013 at 2:31
  • And where/when does that function run/gets executed?
    – kaiser
    Aug 14, 2013 at 11:35
  • I'm sorry I was wrong ,I fixed the code. Aug 14, 2013 at 11:40
  • 2
    Never!, ever hook into gettext, ngettext and similar without instantly removing the attached callbacks! Those filters trigger hundreds of times on each request and can pull your site down to its knees. Seriously. Don't do this.
    – kaiser
    Aug 14, 2013 at 11:48

2 Answers 2

1
/**
 * Changes Label of Admin Menu items
 * @global array $menu
 * @global array $submenu
*/
function change_post_menu_label() {
   global $menu;
   global $submenu;
   $menu[2][0] = 'Home'; 
   $menu[5][0] = 'Articles';
   $submenu['edit.php'][5][0] = "All Articles";
   //    var_dump($submenu);
   //    var_dump($menu);
    echo '';
  }
  if(!is_super_admin()){
    add_action( 'admin_menu', 'change_post_menu_label' );
  }

You can print the array

echo "<pre>";
print_r($menu);
echo "</pre>"; //remove this code after, it is just used to check the index of element in Menu to rename it.

and see elements index to change name for whatever item you'would like to rename. Like in above function I'm renaming the "Posts" in menu to "Articles".

To rename the child of Menu item use

$submenu 

array. For renaming Dashboard to "Home"

  $menu[2][0] = 'Home'; 

add this line to previous function, confirm the index "2" in $menu array for Dashboard.

2
  • thanks bro...how can i rename the "Dashboard" menu to "Home"? Aug 14, 2013 at 11:35
  • I've updated the answer
    – Kumar
    Aug 14, 2013 at 11:47
1

You need to check the user role. Setup a condition like this:

if(current_user_can("manage_network")) add_action("rename_admin_menu_items","your-hook");

References: User roles

1
  • doesn't work, How should the entire code? Aug 14, 2013 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.