Hi friends, this is a very quick WordPress tutorial which demonstrates how to restrict admin panel to administrators access only.
This is the best idea to keep away your website users from admin area access. This is the very simple function which restricts non-admin users to visit the administrator screens.
Open functions.php file and copy paste below code at the end of the file and save it.
if (!array_key_exists('administrator', $current_user->caps))
wp_redirect( get_bloginfo('url') );
add_action('admin_init', 'restrict_admin_access', 1);
If you like this tutorial, share this with your friends via social media channel and also subscribe our newsletter to get the best tutorials directly in your email inbox.
Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies. View all posts by Prem Tiwari