Redirect to previous page after login not working

Hi Folks,

Hoping that someone can help me figure this out.

I want that users after login in to redirect to the previous page. Just before they were sent to the membership options page to login.

I tried the shortcode
[s2Member-Login signup_url="" login_redirect="%%previous%%" title="" show_summary_if_logged_in=“1” profile_title=“You’re already logged in.” display_gravatar=“0” my_account_url="" /]

and the widget. But they are always redirected to the homepage.

Thanks for the time and hope someone can help.


I am not sure I understand what you are saying is currently happening, but I think you are saying this:

  1. User comes to site and gets redirected to the MOP.
  2. User then goes to the Login page and logs in.
  3. User is redirected to the Login Welcome Page (LWP).

If that’s right, that’s exactly as expected because the “previous page” was, in fact, the Login page.

Hi Tim,

Thanks for the time to respond to my question. But maybe i did not explained myself in the best way.

The user path is

  1. reaches a page where has protected content (i’m using this with shortcode [s2If is_user_logged_in()] ) and has the login button that send you to the membership options page
  2. Goes to the login page and enters is info
    3 its gets redirected to the homepage despite i setting it to go to login_redirect="%%previous%%"

Can you still help me figure this out.


I have already explained why your points 2 and 3 work the way they do. The “previous page” under your setup is the login page, so it is never going to work the way you want.

I think your problem is with your point 1. I don’t understand when you say “login button that sends you to the membership options page.” What login button?

Hi Tim,

I created a page and added a button to the login like this, so that the only content blocked is this (in this case a download file)

And used this code to achieve it

<?php echo s2member_pro_login_widget(); ?>

[s2If current_user_can(access_s2member_level0)]
[av_textblock size=’’ font_color=’’ color=’’ av-medium-font-size=’’ av-small-font-size=’’ av-mini-font-size=’’ custom_class=‘secc_h1_noletterspace secc_underline’ admin_preview_bg=’’ av_uid=‘av-mlckmoi’]
The Download
[av_hr class=‘invisible’ height=‘20’ shadow=‘no-shadow’ position=‘center’ custom_border=‘av-border-thin’ custom_width=‘100%’ custom_border_color=’#f0f0f0’ custom_margin_top=‘15px’ custom_margin_bottom=‘15px’ icon_select=‘no’ custom_icon_color=’’ icon=‘ue808’ font=‘entypo-fontello’ custom_class=’’ admin_preview_bg=’’ av_uid=‘av-m8cb7ea’]
[wpdm_package id=‘19021’]
[s2If !is_user_logged_in()]
To access content please login
[av_button label=‘Login’ link=‘page,17659’ link_target=’’ size=‘small’ position=‘center’ label_display=’’ icon_select=‘no’ icon=‘ue800’ font=‘entypo-fontello’ color=‘theme-color’ custom_bg=’#444444’ custom_font=’#ffffff’ av_uid=‘av-i6oyx0y’ custom_class=’’ admin_preview_bg=’’]

If what i’m doing is wrong, how can i get the user to go back to the page where he hit the login button, after doing the login itself.

Thanks for your help.

You need to put the login button on the Membership Options Page.

@sirl78 Try this:

echo '<a href="'.site_url('/wp-login.php?redirect_to='.esc_url($_SERVER['REQUEST_URI'])).'">You must log in or create account to purchase this product</a>';

Note that this is PHP code, so you may need to place it between <?php and ‘?>’ tags.

1 Like

Thanks guys for the effort.

Decided to remove the button (which was sending to a login page) and add the login it self, using the s2menber shortcode.

And worked fine :slight_smile:

Thanks again.


1 Like