Forums

External login page (2 posts)

  1. thomas_n
    Member
    Posted 1 year ago #

    i have a centralized login page for all my WordPress users (running different sites). It submits the username and password to wp-login.php and this works. (see this page

    However, what I want is that users who try to login to their wordpress install directly using wp-login.php are redirected to this page.

    Any idea how to do this without braking the WordPress installation?

  2. thomas_n
    Member
    Posted 1 year ago #

    Nevermind. Found the solution. Add this to functions.php in your theme:

    function external_login() {
    	if (!is_user_logged_in() && !$_POST['username'])
    	{
    		echo '<script language="JavaScript">
    		<!--
    			 window.location="http://your.url/";
    		//-->
    		</script>';
    	}
    
    }
    
    add_action('login_head', 'external_login');

    Basically this checks if the user is logged in and/or the 'username' field is set. If neither is true, then it inserts some javascript that redirects the user to an external login page. On this page you can construct your own login form.

    (ps. now why would I want to do this? I redirect all of my users for their applications to my central hosting pages so I can use these to inform them on changes in infrastructure and so forth. Yes, you could call it 'marketing'.)

Topic Closed

This topic has been closed to new replies.

About this Topic