Skip to content

Instantly share code, notes, and snippets.

@rali14
Last active August 5, 2020 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rali14/85b0b2cc97c6122704e7bb21593fbcf8 to your computer and use it in GitHub Desktop.
Save rali14/85b0b2cc97c6122704e7bb21593fbcf8 to your computer and use it in GitHub Desktop.
Redirect user to a specific URL if logged in from another specific URL
/**
* Redirect user to a specific URL if logged in from another specific URL
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*
* Author: Rashid - https://w3plus.ca
*/
function w3_login_redirect( $redirect_to, $request, $user ) {
// This is the URL that the user is coming from
$fromURL = "https://w3plus.ca/about-us/";
// This is the URL the user will be redirected to
$toURL = "https://w3plus.ca/contact-us/";
// Here is where we do the checks
if ( $request == $fromURL ) {
return $toURL;
} else {
// Otherwise do the default
return $redirect_to;
}
}
add_filter( 'login_redirect', 'w3_login_redirect', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment