• I have an SSO app in salesforce which works perfectly- people click the login button in the top header on our website, it takes them to the custom salesforce login page, they authenticate and then get redirected back to our website’s homepage where they are now logged in.

    Is there any functionality where it redirects them back to the page they are on? Right now, no matter what page they are on, when they hit the login button it takes them back to the homepage after authneticating.

    I understand the callback URL is configured on the SSO app’s side, but I can’t figure out how to work with that to get back to the previous page.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author BERJAYAPaul Ryan

    (@figureone)

    Try generating the login button in your header with wp_login_url( get_permalink() ); . This will tell WordPress to redirect to the current page after logging in: https://developer.wordpress.org/reference/functions/wp_login_url/

    Alternatively, you can specify which page to go to after logging in by adding the redirect_to querystring param to the wp-login.php URL, such as: https://example.com/wp-login.php?redirect_to=https%3A%2F%2Fexample.com%2Fsome-page%2F

    Just make sure to urlencode your URL in the param (e.g., forward slashes replaced with %2F).

    Thread Starter BERJAYAabrownosls

    (@abrownosls)

    Thank you for your help, Paul.

    I am not much of a wordpress expert. The login button is just an HTML code with a link to go to https://mysite.com/wp-login.php?external=oauth2&id=1

    Are you saying to use wp_login_url( get_permalink() ); with the “/wp-login.php?external=oauth2&id=1” part at the end of the code in the HTML?

    Plugin Author BERJAYAPaul Ryan

    (@figureone)

    You would need to use the wp_login_url( get_permalink() ); php snippet in your theme code if you want to generate a login link that would always redirect to the current page after logging in (wp_login_url() generates the login link, and get_permalink() generates the link to the current page and sets it as the redirect_to destination).

    If you’re using the Block Editor, you can also use the “Login/out” block and enable the “Redirect to current URL” toggle, which will accomplish the same thing (set the redirect_to param to wp-login.php).

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Redirect to specific URLs’ is closed to new replies.