How to hide the Weglot admin button for non administrator roles

In this example, we hide the Weglot button in the top navigation for users without the role of administrator

if(is_user_logged_in()){
	$user = wp_get_current_user();
	if ( !in_array( 'administrator', (array) $user->roles ) ) {
		add_action( 'admin_head', 'hide_wg_button' );
	}
}

function hide_wg_button() {
 echo "<style>#wp-admin-bar-weglot{display:none;}</style>";
}

Last updated