Restrict Access to wp-admin by IP Address or redirect

Home Forums BulletProof Security Pro Restrict Access to wp-admin by IP Address or redirect

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #35432


    Anyone got the right .htaccess configuration line and location to put it in BPS Pro to restrict wp-admin login by IP Address ?

    Possibly a redirect to the front page if not from the correct IP ?


    AITpro Admin

    See this Bonus Custom Code forum topic for the code and steps to add Login page/wp-admin backend IP address blocking/restricting code > Notes:  Blocking/restricting the Login page/WordPress wp-admin backend will prevent other people from registering, logging in and posting on a website.  The only time you should restrict/block your Login page/wp-admin backend by IP address is when you are the only person who logs into your website.  If you do not have a Static public IP address assigned by your ISP then you will need to change your IP address manually in your Root htaccess file by using FTP or your web host control panel file manager when your IP address is changed by your ISP.

    Recommended Instead:  Create this custom code below in your themes functions.php file that redirects non-Administrators somewhere else like your website home page.

    add_action( 'admin_init', 'redirect_non_admin_users' );
    // Redirect authenticated non-admins from /wp-admin to the home page / URI
    // This keeps all non-admins out of the /wp-admin area.
    function redirect_non_admin_users() {
    	if ( ! current_user_can( 'manage_options' ) && ! preg_match( '#\/wp-admin\/admin-ajax\.php#', esc_html( $_SERVER['REQUEST_URI'] ) ) ) {
    		wp_safe_redirect( home_url( '/' ), 302 );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.