0

I need to remove the link to the Jetpack settings, but not the links to Omnisearch and Site Stats from the admin menu for everyone not having an administrator role:

enter image description here

For this, I came up with this code:

function remove_posts_menu() {
    if (!current_user_can('administrator')) {
        remove_submenu_page('admin.php?page=jetpack', 'admin.php?page=jetpack');
    }
}
add_action('admin_init', 'remove_posts_menu');

(Reference for the remove_submenu_page() function)

However, this doesn't work. I did check that the function is called and so by adding remove_submenu_page('tools.php', 'tools.php'); - when this is added to the function, just after the removal of the Jetpack settings link, the Tools link is removed, but the Broken Link Checker link (of a plugin I installed) is still visible.

What's the correct way to remove the Jetpack link?

0

Try this instead:

function remove_posts_menu() {
    if ( ! current_user_can( 'manage_options' ) ) 
        remove_submenu_page( 'jetpack', 'jetpack' );

}
add_action( 'admin_init', 'remove_posts_menu' );

where the menu slug and submenu slug are jetpack.

| improve this answer | |
  • Although this works, I discovered it causes conflicts with other elements in the dashboard (e.g. you can't access the Media Library in the "Add Media" modal). I would suggest hooking in admin_menu instead. – jeherve Jul 7 '14 at 10:54
2

Jetpack's menu is added quite late, so you'll need to change the default priority to remove it a bit later (priority 999), like so:

function jetpackme_remove_jetpack_menu() {
        if ( ! current_user_can( 'manage_options' ) ) {
                remove_submenu_page( 'jetpack', 'jetpack' );
        }
}
add_action ( 'admin_menu', 'jetpackme_remove_jetpack_menu', 999 );
| improve this answer | |
0
function remove_menus(){
if ( ! current_user_can( 'administrator' ) ) {
remove_menu_page( 'jetpack' );
}
}
add_action( 'admin_menu', 'remove_menus', 999 );

This seemed to work for me and allowed me to only give access to administrators. You can adapt it to hide any page from the Wordpress list here.

| improve this answer | |

Your Answer

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