WordPress disable dashboard for non-admin

By adding this function to your functions.php, non-admin users can’t approach the WordPress admin / dashboard.

// No WordPress admin for non-administrators
add_action('admin_init', 'no_mo_dashboard');
function no_mo_dashboard() {
 if (!current_user_can('manage_options') && $_SERVER['DOING_AJAX'] != '/wp-admin/admin-ajax.php') {
 wp_redirect(home_url()); exit;
 }
}

I have used this in a project where I created a complete dashboard in the frontend of the website, so where no non-admin user was allowed to visit the WordPress admin / dashboard.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s