After adding this code, the background login function of WordPress can be disabled, and non administrator users are prohibited from logging into the background of the website
If your website does not have front-end login and user center functions, please carefully add 。 If an unexpected situation occurs, you can delete the relevant code on the server side.
In the subject's functions.php Filed Add the following code
/** *Prohibit non administrators from accessing the background and restrict access to background login registration * @package bertly */ function redirect_non_admin_users() { if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_ SERVER['PHP_SELF'] ) { wp_redirect( home_url() ); exit; } } add_action( 'admin_init', 'redirect_non_admin_users' ); add_action('login_enqueue_scripts','login_protection'); function login_protection(){ header('Location: /'); } /** * End */
Code Preview:
Prohibit non administrators from accessing the background and restrict access to background login registration
Extraction code: None
Decompression code: None