Simple Membership Plugin › Forums › Simple Membership Plugin › Back to page after login
- This topic has 8 replies, 4 voices, and was last updated 6 years, 9 months ago by
mbrsolution.
-
AuthorPosts
-
January 1, 2018 at 3:18 am #12842
Rin Ng
ParticipantHi,
Is there a way to redirect the user back to the very same page after they login? I’ve added the login form on the sidebar so that the user can login on every page on the website and would love that the plugin can redirect the user back to the very same page they are at when they login.
Thanks,
RinJanuary 1, 2018 at 11:45 pm #12843mbrsolution
ModeratorHi, please install the following plugin. Let me know if this helps you.
Thank you
January 3, 2018 at 6:30 pm #12865Rin Ng
ParticipantHi mbrsolution,
I’ve installed the plugin. Selected the checkbox but it doesn’t do anything. I’m using the shortcode [swpm_login_form] , read the online documentation below and it writes there is a query “swpm_redirect_to” parameter which is tagged to the form.
https://simple-membership-plugin.com/configure-login-redirection-members/
Is it possible to edit the login form so that it includes the parameter for every single page or sidebar that uses the shortcode [swpm_login_form]?
Thanks again.
Rin
January 3, 2018 at 10:51 pm #12868mbrsolution
ModeratorHi, the plugin/addon does work because I have tested this myself. Can you carry out the following test. Let me know how you go.
Thank you
January 7, 2018 at 6:57 am #12888Rin Ng
ParticipantHi mbrsolution,
I managed to get the redirection to work by editing the login form adding a hidden input field
<input type="hidden" id="swpm_redirect_to" name="swpm_redirect_to" value="<?php echo (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>"/>This will redirect the user back to the very same page where they login, good for websites that has a login panel on every page.
Thanks for the help.
January 7, 2018 at 8:59 pm #12892mbrsolution
ModeratorThank you for sharing your solution. I will report this to the developers so they can investigate further your code.
Kind regards.
January 8, 2018 at 3:11 am #12906admin
KeymasterThats cool. You should actually use the following filter of the plugin to add that hidden input field to the login form. That way the code won’t get lost after a plugin upgrade.
swpm_before_login_form_submit_buttonThe following documentation has explanation:
https://simple-membership-plugin.com/simple-membership-filter-hook-reference/November 27, 2019 at 12:31 am #19328akkatips
ParticipantI know this thread is quite old now, however I am attempting to place this code in the functions.php file of my theme but having no luck.
add_filter('swpm_before_login_form_submit_button', 'login_form_addition');?> function login_form_addition($output) { //Add any extra text message or input fields to the login form output. $output .= '<input type="hidden" id="swpm_redirect_to" name="swpm_redirect_to" value="<?php echo (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>"/>'; return $output; }However it seems like the <?php is causing an error. Any suggestions for this?
November 27, 2019 at 8:03 pm #19333mbrsolution
Moderator@akkatips, have you tried the following addon?
https://wordpress.org/plugins/simple-membership-after-login-redirection/
There is a new feature that allows the member to be redirected back to the page they logged in from.
Regards
-
AuthorPosts
- You must be logged in to reply to this topic.