# SSO with wordpress help

**URL:** https://meta.discourse.org/t/sso-with-wordpress-help/80315
**Category:** WordPress
**Created:** [February 11, 2018, 5:12pm UTC](https://meta.discourse.org/t/sso-with-wordpress-help/80315 "2018-02-11T17:12:36Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![dena\_blaze](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@dena\_blaze](https://meta.discourse.org/u/dena_blaze)
#### Post date: [February 11, 2018, 5:12pm UTC](https://meta.discourse.org/t/sso-with-wordpress-help/80315/1 "2018-02-11T17:12:36Z")

</div>

Hi, I have sso set up with the wp-discourse plugin but am having problems redirecting users back to my discourse site once they login through my wordpress site. Is this possible?

---

<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: [February 11, 2018, 5:20pm UTC](https://meta.discourse.org/t/sso-with-wordpress-help/80315/2 "2018-02-11T17:20:46Z")

</div>

Yes, users should be automatically redirected back to Discourse after logging into WordPress. Sometimes the redirect gets overridden by other plugins. Do you have any plugins on your WordPress site that could be affecting the login redirect?

---

<div class="post-metadata">

### Author: ![dena\_blaze](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@dena\_blaze](https://meta.discourse.org/u/dena_blaze)
#### Post date: [February 11, 2018, 6:27pm UTC](https://meta.discourse.org/t/sso-with-wordpress-help/80315/3 "2018-02-11T18:27:11Z")

</div>

I am using [wordfence security plugin](https://wordpress.org/plugins/wordfence/) which I’ve tried deactivating but still no redirect. Also for my login I am using [profile builder](https://wordpress.org/plugins/profile-builder/) instead of the default wp login.

---

<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: [February 11, 2018, 6:41pm UTC](https://meta.discourse.org/t/sso-with-wordpress-help/80315/4 "2018-02-11T18:41:04Z")

</div>

The issue is probably being caused by the profile builder plugin. If the plugin has any options to do with login redirects, you could try disabling them and see if that makes a difference. I’ll install that plugin on my test site and take a look at it, because I think this has come up before. I won’t be able to try it until tomorrow.

---

<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: [February 12, 2018, 12:45am UTC](https://meta.discourse.org/t/sso-with-wordpress-help/80315/5 "2018-02-12T00:45:58Z")

</div>

I’ve tried it out and there is a conflict with the way the profile builder plugin handles the login redirect and the redirect that’s required for [Discourse SSO](https://meta.discourse.org/t/13045?silent=true) to work correctly. There is a fix for it. I’ll try to add it to the plugin this week.

---

<div class="post-metadata">

### Author: ![dena\_blaze](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@dena\_blaze](https://meta.discourse.org/u/dena_blaze)
#### Post date: [February 13, 2018, 7:56am UTC](https://meta.discourse.org/t/sso-with-wordpress-help/80315/6 "2018-02-13T07:56:51Z")

</div>

Thanks @simon am looking forward to it.

---

<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: [February 14, 2018, 2:23am UTC](https://meta.discourse.org/t/sso-with-wordpress-help/80315/7 "2018-02-14T02:23:30Z")

</div>

Are you able to add some code to your theme’s `functions.php` file? Adding this code should redirect users back to Discourse after logging in through WordPress for sites that are using the Profile Builder plugin.

```php
add_filter( 'login_redirect', 'wpdc_login_redirect_override' );
function wpdc_login_redirect_override( $redirect ) {
    $output = [];
	parse_str( parse_url( $redirect, PHP_URL_QUERY ), $output );
	if ( isset( $output['redirect_to'] ) ) {
	    return $output['redirect_to'];
    }

    return $redirect;
}

```

I’m assuming that you have already set the path to your login page on the plugin’s SSO Provider tab. If not, you should set it here:

 ![07%20PM](https://global.discourse-cdn.com/meta/original/3X/b/d/bd64c406483c4b3ecd2f8bd0fdc926f49124cf31.png)

I would prefer for people to not have to add any custom code to get things working. I’ll look into this some more and see if I can add it to the plugin’s code.

If you have any questions about this, please ask.

---

<div class="post-metadata">

### Author: ![dena\_blaze](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@dena\_blaze](https://meta.discourse.org/u/dena_blaze)
#### Post date: [February 14, 2018, 1:10pm UTC](https://meta.discourse.org/t/sso-with-wordpress-help/80315/8 "2018-02-14T13:10:36Z")

</div>

It worked, thank you @simon for your help.

---

<div class="post-metadata">

### Author: ![CodySullivan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codysullivan/32/141986_2.png) [@CodySullivan](https://meta.discourse.org/u/CodySullivan)
#### Post date: [May 24, 2019, 7:38am UTC](https://meta.discourse.org/t/sso-with-wordpress-help/80315/9 "2019-05-24T07:38:30Z")

</div>

I have the same original issue as @dena_blaze and am also using the Profile Builder plugin. I added this code to my `functions.php` file and it doesn’t seem to work.

I could try using [the solution you had here](https://meta.discourse.org/t/wp-discourse-login-page-path/103780/2) of creating an entirely separate login page via Profile Builder and then setting a redirect to my Discourse forum homepage, but that seems like an unnecessary workaround, and it would be more ideal to use this solution since my understanding is that it would redirect the user back to the exact forum page they were looking at previously (not just the homepage as a catch-all).

Any updates on whether this has been added to the plugin’s code, and/or is it likely something may have changed with Profile Builder to need a different solution?

---

<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: [May 24, 2019, 5:01pm UTC](https://meta.discourse.org/t/sso-with-wordpress-help/80315/10 "2019-05-24T17:01:27Z")

</div>

> [@CodySullivan](#):
>
> Any updates on whether this has been added to the plugin’s code, and/or is it likely something may have changed with Profile Builder to need a different solution?

This has not been added to the [WP Discourse](https://github.com/discourse/wp-discourse) code. If the code snippet from my previous post is not working for you, then it seems likely that something has changed with the Profile Builder plugin. I’ll take a look at what’s going on with it.

Edit: I just installed the Profile Builder plugin and configured it to ‘Enable Private Website.’ My login page on WordPress is at `/log-in`

When I set the [WP Discourse](https://github.com/discourse/wp-discourse) ‘Path to your Login Page’ option to `/log-in`, and add the following code to my theme’s `functions.php` file, I am being correctly redirected back to Discourse during the SSO login process:

```php
add_filter( 'login_redirect', 'wpdc_login_redirect_override' );
function wpdc_login_redirect_override( $redirect ) {
    $output = [];
    parse_str( parse_url( $redirect, PHP_URL_QUERY ), $output );
    if ( isset( $output['redirect_to'] ) ) {
        return $output['redirect_to'];
    }

    return $redirect;
}

```

If this isn’t working for you, it’s possible that the problem is being caused by something other than the Profile Builder plugin.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2024, 12:37pm UTC](https://meta.discourse.org/t/sso-with-wordpress-help/80315/11 "2024-06-08T12:37:12Z")

</div>

This topic was automatically closed after 2308 days. New replies are no longer allowed.
