最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Remove Elementor Menu From Wordpress Admin

programmeradmin0浏览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
};

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
};
Share Improve this question edited Jul 10, 2018 at 17:01 Krzysiek Dróżdż 25.5k9 gold badges53 silver badges74 bronze badges asked Jul 10, 2018 at 14:32 Amit JugranAmit Jugran 1311 silver badge9 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 3

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 );

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.

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' );
}
发布评论

评论列表(0)

  1. 暂无评论