Home > Blockchain >  Redirecting wp-login.php makes log in button keep redirect to the same custom log In page the page
Redirecting wp-login.php makes log in button keep redirect to the same custom log In page the page

Time:03-31

I have copied wp-login.php code in a template file in my theme Created a new page and assigned the template /login

Added the following code in function.php

    // 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 custom login page url
        $page = '/login';
        // Redirect to the custom login page
        wp_redirect($page);
        // Stop execution to prevent the page loading for any reason
        exit();
    }
}

the page keeps directing me to the login after pressing the login button

CodePudding user response:

that's not the home page thats login page... change page to...

`$page = get_site_url();`

CodePudding user response:

I have found I solution from https://agconsulting.altervista.org/all-you-need-to-know-about-wp-customize-login-page-without-plugin/

the code in the function.php file is:

function redirect_login_page()
{
    $login_page  = home_url('/login/');
    $page_viewed = basename($_SERVER['REQUEST_URI']);

    if ($page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {
        wp_redirect($login_page);
        exit;
    }
}
add_action('init', 'redirect_login_page');
  • Related