0

How to remove elementor from wordpress admin menu. I have tried below option but it didnt work.

add_action( 'admin_menu', 'my_remove_menu_pages' );
function my_remove_menu_pages() {
    remove_menu_page( 'edit.php?post_type=elementor_library' );                   
    //Elementor
};
0

I have been able to do it using 'admin_init' action. The correct code is below

add_action( 'admin_init', 'my_remove_menu_pages' );
function my_remove_menu_pages() {

global $user_ID;

if ( current_user_can( 'subscriber' ) ) 
{
remove_menu_page( 'edit.php?post_type=elementor_library' );
remove_menu_page( 'elementor' );
}
}

However, I am not able to restrict it for a specific user role. The above code restricts it for all user roles, including admin.

I am using a multisite install. so if anyone knows to restrict it for a user role on multisite install, please add the necessary bit of code.

Thanks.

  • 2
    You should NOT use roles with current_user_can (codex.wordpress.org/Function_Reference/current_user_can): "While checking against particular roles in place of a capability is supported in part, this practice is discouraged as it may produce unreliable results." – Krzysiek Dróżdż Jul 10 '18 at 17:00
  • Even an admin "can" subscriber. To hide it for everyone except admins, change the condition to if(current_user_can('activate_plugins')). – WebElaine Sep 17 '18 at 18:47
0

This would work for editors. You can swap the role in and out depending on which role you are trying to target (e.g., editor, subscriber, etc.). This would go in functions.php of your child theme.

function remove_menus(){
// get current login user's role
$roles = wp_get_current_user()->roles;

// test role
if( !in_array('editor',$roles)){
return;
}

//remove menu from site backend.
remove_menu_page( 'edit.php?post_type=elementor_library' ); // Elementor Templates
remove_menu_page( 'elementor' ); // Elementor
}
add_action( 'admin_menu', 'remove_menus' , 100 );
-1

This code works for admins only.

add_action( 'admin_init', 'my_remove_menu_pages' );
function my_remove_menu_pages($query) {
     $current_user = wp_get_current_user();
        if($current_user->ID == 1) //Aqui é o meu ID. Vai ocultar a página pra todos menos pra esse ID
                return $query;
remove_menu_page( 'edit.php?post_type=elementor_library' );
remove_menu_page( 'elementor' );
}
  • The user ID and the role are not related. User nr. 1 might be just a normal user. – fuxia Sep 17 '18 at 20:43

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.