# SSO redirect link

**URL:** https://meta.discourse.org/t/sso-redirect-link/84200
**Category:** WordPress
**Created:** [March 30, 2018, 4:30am UTC](https://meta.discourse.org/t/sso-redirect-link/84200 "2018-03-30T04:30:27Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Sami\_Syed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sami_syed/32/93193_2.png) [@Sami\_Syed](https://meta.discourse.org/u/Sami_Syed)
#### Post date: [March 30, 2018, 4:30am UTC](https://meta.discourse.org/t/sso-redirect-link/84200/1 "2018-03-30T04:30:27Z")

</div>

I am using wordpress as a SSO client to discourse.

How do I set it up so a user is sent back to the page he/she was on after logging in.

Here is what my SSO URL looks like:

> **[Class B Camper Van Concierge for Retirees | Project Vanlife](https://projectvanlife.com/?discourse_sso=1&redirect_to=http%3A%2F%2Ftheprojectvanlife.com%2F)**
>
> Buying a Class B camper van shouldn't take a year of research. We match you to the right certified builder so you can stop comparing and start traveling.

As you can see it redirects to my website homepage. Could I edit this link to redirect the user back to the page he was on? will this mess up the SSO?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [April 2, 2018, 5:10pm UTC](https://meta.discourse.org/t/sso-redirect-link/84200/2 "2018-04-02T17:10:17Z")

</div>

> [@Sami\_Syed](#):
>
> Could I edit this link to redirect the user back to the page he was on?

Yes, you can set any page on your WordPress site as the value for `redirect_to`. You probably do not have to URL encode the `redirect_to` parameter. Something like this should work:

```plaintext
http://theprojectvanlife.com/?discourse_sso=1&redirect_to=http://theprojectvanlife.com/my-wordpress-page

```

---

<div class="post-metadata">

### Author: ![Sami\_Syed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sami_syed/32/93193_2.png) [@Sami\_Syed](https://meta.discourse.org/u/Sami_Syed)
#### Post date: [April 2, 2018, 11:51pm UTC](https://meta.discourse.org/t/sso-redirect-link/84200/3 "2018-04-02T23:51:26Z")

</div>

so by adding “my-wordpress-page” as the redirect it will redirect user to the page he/she was on?  
Or did you mean to replace “my-wordpress-page” with the page I want the user redirected to?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [April 2, 2018, 11:58pm UTC](https://meta.discourse.org/t/sso-redirect-link/84200/4 "2018-04-02T23:58:15Z")

</div>

> [@Sami\_Syed](#):
>
> Or did you mean to replace “my-wordpress-page” with the page I want the user redirected to?

Yes. set the `redirect_to` parameter to the URL of the page you want users to end up on.

---

<div class="post-metadata">

### Author: ![Sami\_Syed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sami_syed/32/93193_2.png) [@Sami\_Syed](https://meta.discourse.org/u/Sami_Syed)
#### Post date: [April 3, 2018, 12:02am UTC](https://meta.discourse.org/t/sso-redirect-link/84200/5 "2018-04-03T00:02:13Z")

</div>

Is it possible to setup a redirect to link that just sends them back to the same page they were on?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [April 3, 2018, 1:33am UTC](https://meta.discourse.org/t/sso-redirect-link/84200/6 "2018-04-03T01:33:31Z")

</div>

> [@Sami\_Syed](#):
>
> Is it possible to setup a redirect to link that just sends them back to the same page they were on?

You can use the `[discourse_sso_client]` shortcode on any WordPress page to create a ‘Login with Discourse’ link that will redirect users back to the page that the shortcode was placed on.

There is some documentation on the plugin’s SSO Client tab for the shortcode.

There was a bug in the most recent versions of the plugin that was causing the shortcode to display the ‘Link your account with Discourse’ text for logged in users who had already linked their account. Update to [WP Discourse](https://github.com/discourse/wp-discourse) version 1.6.0 to get the fix.

---

<div class="post-metadata">

### Author: ![Golaxo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/golaxo/32/207301_2.png) [@Golaxo](https://meta.discourse.org/u/Golaxo)
#### Post date: [February 5, 2021, 7:56am UTC](https://meta.discourse.org/t/sso-redirect-link/84200/7 "2021-02-05T07:56:13Z")

</div>

Hey, I think it would be an easy but great addition to the plugin’s functionality if you could implement this too: [Stand alone signup form/link?](https://meta.discourse.org/t/stand-alone-signup-form-link/50558/3). I am using Discourse as SSO master and it would be very useful to provide both a login page for the existing and a registration link for new users with the redirection to the original page they came from.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [February 8, 2021, 11:42am UTC](https://meta.discourse.org/t/sso-redirect-link/84200/8 "2021-02-08T11:42:17Z")

</div>

Hey, we don’t have any current plans to implement anything here beyond the `redirect_to` param.

It’s a little more complicated than it seems to “redirect someone back to the same page they were on”. There are quite a few edge cases. If we added that as a core feature we’d effectively be signing up to support all those edge cases as well 🙂 As you might imagine, there are a lot of different ways to configure a Wordpress site.

I gave you a bit of a [hint on this already](https://meta.discourse.org/t/sso-dynamic-login-and-registration-redirect-url/178106/2), but to help you along a bit more, you or your developer will want to do something like this, namely extend the existing shortcode to automatically set the `route_to` to the current url of the site. You can then figure out the edge cases for that for your own specific site.

In `functions.php`

```plaintext
use WPDiscourse\SSOClient\SSOClientShortcode;

function render_discourse_sso_client_link_with_redirect() {
    $sso = new SSOClientShortcode();
    $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http");
    $current_url = "$protocol://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $options = array(
      "redirect" => $current_url,
      "login" => "Login"
    );
    return $sso->discourse_sso_client_shortcode( $options );
}
add_shortcode( 'discourse_sso_client_link_with_redirect', 'render_discourse_sso_client_link_with_redirect' );

```

Then in your template use the shortcode `[discourse_sso_client_link_with_redirect]`

---

<div class="post-metadata">

### Author: ![Golaxo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/golaxo/32/207301_2.png) [@Golaxo](https://meta.discourse.org/u/Golaxo)
#### Post date: [February 8, 2021, 2:35pm UTC](https://meta.discourse.org/t/sso-redirect-link/84200/9 "2021-02-08T14:35:51Z")

</div>

Thank you, it helps a lot, mate!
