Intro
If you want to limit access to the WordPress Dashboard based on user role, you can do so with either code or a plugin.
With Code
You can put the following code in your functions.php file to limit Dashboard access to only admins. More info can be found here and here.
<?php // For implementation instructions see: https://aceplugins.com/how-to-add-a-code-snippet/
/**
* Block wp-admin access for non-admins
*/
function ace_block_wp_admin() {
if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_safe_redirect( home_url() );
exit;
}
}
add_action( 'admin_init', 'ace_block_wp_admin' );
You can change the home_url() to something else if you want to redirect them somewhere else. For example, to redirect them to the shop page you can use home_url( '/shop' ) or if you have a profile page home_url( '/profile' ).
With a Plugin
Or you can use a plugin to accomplish this. Get the Remove Dashboard Access plugin and don’t bother with code.


Leave a Reply