Redirect After Login
-
One issue I had with this plugin that after logging in, the user was directed to the homepage rather than the page s/he signed up from. Here’s what I did to redirect:
In /includes/lib/PkliLogin.php, somewhere around line 115:
// This function displays the login button on the default WP login page public function display_login_button() { // User is not logged in, display login button echo "<p><a rel='nofollow' href='" . $this->get_auth_url() . "'> <img alt='LinkedIn' src='" . PKLI_URL . "includes/assets/img/linkedin-button.png' /> </a></p>"; }
Becomes:
// This function displays the login button on the default WP login page public function display_login_button() { $currentURL = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; setcookie('li_redirect', $currentURL, 0, COOKIEPATH, COOKIE_DOMAIN, false); // User is not logged in, display login button echo "<p><a rel='nofollow' href='" . $this->get_auth_url() . "'> <img alt='LinkedIn' src='" . PKLI_URL . "includes/assets/img/linkedin-button.png' /> </a></p>"; }
Around line 406, change:
// Default fields return "<a href='" . $auth_url . "' class='$class'><img src='" . $img . "' /></a>"; }
to:
// Default fields $currentURL = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; setcookie('li_redirect', $currentURL, 0, COOKIEPATH, COOKIE_DOMAIN, false); return "<a href='" . $auth_url . "' class='$class'><img src='" . $img . "' /></a>"; }
This sets a cookie called “li_redirect” with the page URL of the page that they last saw the login button on.
Under Ultimate LinkedIn Integration Plugin Settings, set the Login Redirect URL and Sign-Up Redirect URL to https://www.yourdomain.com/?li=1
Modify your child theme’s header.php to include a hook to look for the ‘li’ variable in the URL and that the ‘li_redirect’ cookie is set:
<?php if((isset($_COOKIE['li_redirect'])) && ($_GET['li'])) { $li_redirect = $_COOKIE['li_redirect']; unset($_COOKIE['li_redirect']); header("Location: ". $li_redirect); } ?>
(Make sure any caching you have in place excludes https://www.yourdomain.com/?li=1)
- The topic ‘Redirect After Login’ is closed to new replies.