Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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