4 comments

  1. Try this

    add_action('init','custom_login');
    function custom_login(){
     global $pagenow;
     if( 'wp-login.php' == $pagenow ) {
      wp_redirect('http://localhost/wordpresstest/blog/');
      exit();
     }
    }
    
  2. Try This Out

    // Hook the appropriate WordPress action
    add_action('init', 'prevent_wp_login');
    
    function prevent_wp_login() {
        // WP tracks the current page - global the variable to access it
        global $pagenow;
        // Check if a $_GET['action'] is set, and if so, load it into $action variable
        $action = (isset($_GET['action'])) ? $_GET['action'] : '';
        // Check if we're on the login page, and ensure the action is not 'logout'
        if( $pagenow == 'wp-login.php' && ( ! $action || ( $action && ! in_array($action, array('logout', 'lostpassword', 'rp', 'resetpass'))))) {
            // Load the home page url
            $page = get_bloginfo('url');
            // Redirect to the home page
            wp_redirect($page);
            // Stop execution to prevent the page loading for any reason
            exit();
        }
    }
    
  3. This works for logging in, but not logging out.
    If you’re to log out, it redirects you back to the login page, without actually logging you out, as the URL parameter to log out includes /wp-login.php/

    I found this to be a better solution:

    // Redirect from /wp-login.php/ to /login/ with ability to logout & redirect 
    add_action('init', 'custom_login');
    function custom_login() {
    global $pagenow;
    if ($pagenow === 'wp-login.php' && empty($_REQUEST['action'])) {
        wp_redirect('https://example.com/login/');
        exit();
    } elseif ($pagenow === 'wp-login.php?action=logout' && $_REQUEST['action'] === 'logout') {
        wp_redirect('https://example.com/');
        exit();
    }
    }
    
  4. You can achieve the results of accessing wordpress admin via custom admin login page using a plugin named All In One WP Security & Firewall.

    The All In One WordPress Security plugin will take your website security to a whole new level. This plugin is designed and written by experts and is easy to use and understand.It reduces security risk by checking for vulnerabilities, and by implementing and enforcing the latest recommended WordPress security practices and techniques.

    Your requirement:

    This plugin has ability to hide admin login page. Rename your WordPress login page URL so that bots and hackers cannot access your real WordPress login URL. This feature allows you to change the default login page (wp-login.php) to something you configure.

    For more features, refer plugin codex

Comments are closed.