Bueller… Bueller? Any help would be greatly appreciated.
I’m in the same boat. I want the simple functionality of a subscriber being able to log in and be automatically returned to the page they were on.
I’ve tried adding a redirect_to hidden field with the login current page url on the login form and I’ve also tried adding ?redirect_to=current_page_url on the form action and nothing works.
Peter’s Redirect plugin is the closest solution I’ve found except it forces you to set one page and one page only for redirection based upon user roles.
Yeah… I looked at Peter’s Redirect plugin, but that’s not really what I’m looking for either.
I looked at the code, and it will set the redirect_url to the $_REQUEST[‘redirect_to’] variable. It just doesn’t seem like anything is being passed to the login via $_POST or $_GET to know where it came from. I know I can go in and hack it, but I just figured there must be a setting that I’m unaware of or a plugin that does what I need (I thought this would be default functionality).
Hey Trey –
I resolved my issue. As soon as I removed a couple of the other plugins I’d tried and removed some custom functions I’d also tried (that I thought I’d deleted), it started working for me. This was all at the theme level for me. Here’s my custom login script since the default redirect_to didn’t seem to want to work (you’ll notice I added it to the form action url):
<form name="loginform" id="loginform" action="<?php echo site_url('wp-login.php', 'login_post') ?>?redirect_to=http://<?=$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];?>" method="post">
<p>
<label><?php _e('Username') ?><br />
<input type="text" name="log" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" tabindex="10" /></label>
</p>
<p>
<label><?php _e('Password') ?><br />
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" tabindex="20" /></label>
</p>
<?php do_action('login_form'); ?>
<p class="forgetmenot"><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="90" /> <?php esc_attr_e('Remember Me'); ?></label></p>
<p class="submit">
<input type="submit" name="wp-submit" id="wp-submit" value="<?php esc_attr_e('Log In'); ?>" tabindex="100" />
<input type="hidden" name="redirect_to" value="http://<?=$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];?>" />
<input type="hidden" name="testcookie" value="1" />
</p>
</form>
Thanks… that worked for me! I was about to bite the bullet and dive in myself. You’re solution works for me though… so I’ll just use it. 🙂