I want to Block all access to Wp-admin and Wp-login.php Pages from all members who are not site Admins.
And I don't want to use any plugin for this.
The flow is that, even if people deliberately type “mydomain.com/wp-admin” or they deliberately type “mydomain.com/wp-login.php” , it should still redirect them to the Login or Register Pages that I have created-- and they should never see the Wp- Admin Page or Wp-login.php Page.
I have this Code:
//Redirect WP Login Page
add_filter( 'login_url', 'my_login_page', 10, 3 );
function my_login_page( $login_url, $redirect, $force_reauth ) {
return home_url( '/my-login-page/?redirect_to=' . $redirect );
}
Unfortunately, if you try to access "mydomain.com/wp-admin", it functions well and redirects you to my specified Page.
But if you deliberately type "mydomain.com/wp-login.php", it still loads the wp-login.php Page.
Please, any PHP Code Snippet that can help me totally block all access to wp-admin and wp-login.php together?
Regards.