WordPress.org

Forums

[resolved] Redirect from default WP to custom login page not working, here's the script (2 posts)

  1. halben
    Member
    Posted 1 year ago #

    I added this to the theme's function.php. I log onto the website and click on login, it still takes me to the default WP login screen.

    /*
     * Newly added custom code (for reference only)
     * --------------------------------------------
     * RedirectWPLogin()
     * Redirect from default WordPress login to custom login page
     */
    
     add_filter('init', 'RedirectWPLogin()');
     function RedirectWPLogin()
     {
     	$request = basename($_SERVER['REQUEST_URI']);
    	if ($request == 'wp-login.php'):
    		wp_redirect(site_url('/login'));
    		exit();
    	endif;
     }

    Can anyone please help me in debugging this problem?

    Thanks,
    Hal

  2. halben
    Member
    Posted 1 year ago #

    Figured it out. Remove the () in the add_filter code.

Topic Closed

This topic has been closed to new replies.

About this Topic