Archived topic
Remove WPSP from Dashboard Menu by User Role
7 replies · Started by Paul on April 16, 2020
I want to remove the WP Show Posts menu item from the left-hand menu in the WP dashboard for certain user roles only, such as Editor. How can I do that? I tried the User Role Editor plugin, but the WPSP post permissions are mixed in with other CPTs post permissions (such as Strong Testimonials and GP Elements and Elementor Templates) and so I need another work-around to just remove WPSP for Editors from the menu altogether. Thanks in advance.

Hi there,
You could try this:
add_action( 'admin_menu', function() {
if ( ! current_user_can( 'manage_options' ) ) {
remove_menu_page( 'edit.php?post_type=wp_show_posts' );
}
}, 500 );
Let me know :)
Nope, didn't work unfortunately. :( (UPDATE: Your revised code above works Tom, thanks!!!)
Hmm, can you try the updated code?: https://generatepress.com/forums/topic/remove-wpsp-from-dashboard-menu-by-user-role/#post-1242245
That did work. And how can I modify it to also exclude the (Elementor) Templates menu item from the left Dashboard menu? Basically I need to exclude both WPSP and Templates from the menu as both affect the design of the site which Editors shouldn't be messing with.
You would duplicate this line: remove_menu_page( 'edit.php?post_type=wp_show_posts' );
But change wp_show_posts to whatever their slug is in the URL.
Hey, that did the trick!
Here's the code I used:
add_action( 'admin_menu', function() {
if ( ! current_user_can( 'manage_options' ) ) {
remove_menu_page( 'edit.php?post_type=wp_show_posts' );
remove_menu_page( 'edit.php?post_type=elementor_library' );
}
}, 500 );
Thanks so much Tom!
You're welcome :)