Skip Navigation

[Gelöst] Redirecting login form based on passed URL parameters

This support ticket is created vor 4 Jahre, 7 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 5 Antworten, has 2 Stimmen.

Last updated by daveG-7 vor 4 Jahre, 7 Monate.

Assigned support staff: Nigel.


I'm trying to use a link to pass a redirect parameter to my login form, so that it can redirect users back to the page they came from. Here's the code I'm using.

Login form:

{!{wpv-login-form redirect_url_fail='<em><u>hidden link</u></em>' allow_remember='true'}!}

PHP to create a shortcode to generate the login link:

 function login_redirect_shortcode() {
$returnPath = get_settings('siteurl') . '/login/?redirect_to=' . urlencode($_SERVER['REQUEST_URI']);
echo "<a href='".$returnPath."'>Link</a>";
add_shortcode('login_redirect', 'login_redirect_shortcode');

This successfully generated the URL hidden link when it's on /about/, which should be correct However, filling out the login form and hitting submit doesn't redirect to that page, it reloads the current page.

If I change the URL generated from /log-in (where my login form is) to /wp-login.php (so, hidden link) the redirect works - when you log in at that URL, you get redirected to the About page. However, I don't want to use the standard WordPress Login, as I've already set up and styled the login form generated by Views.

So, is there anyway to pass a redirect URL like this to a wpv-login-form Login Form?



Sorry, I'd copied the wrong version the php there. The only change is that the line

$returnPath = get_settings('siteurl') . '/login/?redirect_to=' . urlencode($_SERVER['REQUEST_URI']);

should read

$returnPath = get_settings('siteurl') . '/log-in/?redirect_to=' . urlencode($_SERVER['REQUEST_URI']);

Because the login page is at /log-in, not /login



Languages: Englisch (English ) Spanisch (Español )

Timezone: Europe/London (GMT+00:00)

Hi Dave

You have registered the shortcode but don't appear to be using it.

I haven't tried this but I expect you should be able to modify your shortcode so that the URL is simply the page you want to redirect to (the full URL), and then use the shortcode for the redirect_url parameter of the wpv-login-form shortcode, like so:

{!{wpv-login-form redirect_url='[login_redirect]' redirect_url_fail='<em><u>hidden link</u></em>' allow_remember='true'}!}

Do you want to try that and let me know if it works, and if not I'll take a closer look.


That's not quite right. I want the shortcode to be on a different page than the log in form, say /about. So, I want the user, after clicking the link the shortcode creates, to be taken to the login form, and then, when they fill out the form, I want them to be redirected back to /about, or whatever page the link was on. Why I want this is to use it on user-created posts with varying URLS, so that people who aren't logged in can log in and then be sent back to the page they were on to see protected content there. For that reason, just putting the shortcode in the login form won't work, because that would just get the login page URL and reload that page.



Languages: Englisch (English ) Spanisch (Español )

Timezone: Europe/London (GMT+00:00)

Hi Dave

Sorry, I didn't look closely enough at your shortcode to see what it does.

If you use that to link to your custom login page and have added a URL parameter "redirect_to" then you can access that URL parameter on your login page with the wpv-search-term shortcode (, where the param attribute would be 'redirect_to'.

So try using wpv-search-term to generate the redirect_url attribute, like so:

{!{wpv-login-form redirect_url='[wpv-search-term param="redirect_to"]' redirect_url_fail='<em><u>hidden link</u></em>' allow_remember='true'}!}

I haven't tested this but I think it should unless you run into a problem with the shortcode format (using {!{ }!} instead of square brackets because you are adding this to a page builder module. If it doesn't work initially try changing the square brackets around wpv-search-term to the same brace format, and if that doesn't work try changing all to square brackets.


That worked perfectly! Thank you, that was something I'd been trying to get working for weeks.

It's also something that's been asked without resolution several times on these forums (how to have the login form redirect to the previous page). This doesn't work in every situation, just when people follow the link generated by the shortcode, but I still think it could be helpful.

Thanks again!