WP Code Snippet
Preventing Access wp-admin From Users
To more secure wordpress website can preventing access wp-admin from user. Only administrator can be access the site wp-admin.
For prevent access wp-admin from user just take below function in your theme functions.php file.
function jeba_blockusers_init() { if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { wp_redirect( home_url() ); exit; } add_action( 'init', 'jeba_blockusers_init' ); }
Note: Without administrator can give permission author and editor, for this just add author and editor beside administrator like current_user_can( ‘administrator’, ‘author’, ‘editor’ )
Comments are closed