admin管理员组文章数量:1279174
I am currently using the wp-members wordpress plugin. I just learned that they have no functionality to redirect the user to the last page viewed after login or registration .. which has a solution thank you
I am currently using the wp-members wordpress plugin. I just learned that they have no functionality to redirect the user to the last page viewed after login or registration .. which has a solution thank you
Share Improve this question asked Oct 2, 2021 at 15:16 flexi2202flexi2202 175 bronze badges2 Answers
Reset to default 0Give this a try...
function save_url_before_login() {
if(!is_user_logged_in()) {
$_SESSION['referer_url'] = get_the_permalink();
}
add_action('wp', 'save_url_before_login');
and:
function redirect_after_login() {
$redirect_url = home_url('/');
if (isset($_SESSION['referer_url'])) {
$redirect_url = $_SESSION['referer_url'];
unset($_SESSION['referer_url']);
}
return $redirect_url;
}
add_filter('login_redirect', 'redirect_after_login');
I use this code on functions.php
// redirects user after login and logout
if (! function_exists('ctm_login')) {
add_action('wp_login', 'ctm_login');
function ctm_login(){wp_redirect($_POST['link']);exit;}
}
if (! function_exists('ctm_logout')) {
add_action('wp_logout', 'ctm_logout');
function ctm_logout(){wp_redirect($_POST['link']);exit;}
}
however this works because I have a input hidden on the login form
<input type="hidden" name="link" value="<?php echo home_url(add_query_arg(array($_GET), $wp->request));?>">
本文标签: pluginsHow to redirect users to the last page viewed
版权声明:本文标题:plugins - How to redirect users to the last page viewed 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741279188a2369910.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论