I'm trying to remove some item (like 'Commenti') from the WP dashboard for the user Author. I inserted into functions.php this code:

add_action( 'admin_menu', 'my_menu_links_removing', 999 ); 

function my_menu_links_removing() {
    if ( ! current_user_can('administrator') ) {
        remove_menu_page( 'comments.php' );                

The item's name is 'Commenti' (Italian language) and I think that I'm using a wrong string like parameter passed to remove_menu_page function..

Can you help me, please?

Thanks in advance!

1 Answer 1


Two edits: checking for a role is not recommended, you want to check for a capability instead; and the php file you want to pass is edit-comments.php.

add_action( 'admin_menu', 'my_menu_links_removing', 999 ); 
function my_menu_links_removing() {
    if ( ! current_user_can('activate_plugins') ) {
        remove_menu_page( 'edit-comments.php' );                

Administrators are the only default role (besides Super Admin if you're on MultiSite) that can activate plugins, so this still checks to see whether the user is an admin, and if not, the comments menu should disappear.

See also: https://codex.wordpress.org/Function_Reference/remove_menu_page#Examples for a list of other menu pages that can be removed and what their php filenames are.

  • Thank's! But I have to remove others plugins item visibile for the author also, more of them are sepcific plugins of the theme; what is the correct parameter that I gave to pass to the funciton? Feb 23, 2018 at 15:20
  • Just visit each admin page and look at the URL. The PHP file name (parameter) you need to pass is the URL itself. If it is under a submenu rather than being a top-level item lik eComments, there is a different function called remove_submenu_page() which does the same thing for submenu items.
    – WebElaine
    Feb 23, 2018 at 15:26
  • many thanks!! It works but there's some plugins with url like, for example, this: 'admin.php?page=acf-options-property-type'. If I remove 'admin.php' each item is removed but if I remove 'admin.php?page=acf-options-property-type' it doesn't work.. In this case have I to use remove_submenu_page() function? Feb 23, 2018 at 15:51
  • ACF has its own function here - advancedcustomfields.com/resources/…
    – WebElaine
    Feb 23, 2018 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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