I'm trying to redirect users to a certain page when logging in using the wordpress login on a certain page (there's a user/pass input on the homepage, not asking about redirect from site.com/wp-login). The code is below; wpmem_
is from a plugin. This code worked fine when I had a different URL but it's not working since I changed it to shop
.
add_filter( 'wpmem_login_redirect', 'my_login_redirect', 10, 2 );
function my_login_redirect( $redirect_to, $user_id )
{
// return the url that the login should redirect to
return 'http://example.com/shop/';
}
If this is the function that gets called to redirect the user from the login, try to use the code below instead of the return function.
header("Location: http://example.com/shop/");
exit();
Try this one:
add_filter( 'wpmem_login_redirect', 'my_login_redirect', 10, 3 );
function my_login_redirect( $redirect_to, $request, $user )
{
// return the url that the login should redirect to
return home_url('shop');
}
Insted of $_SERVER['HTTP_REFERER']
put your url where you want to redirect
if ( (isset($_GET['action']) && $_GET['action'] != 'logout') || (isset($_POST['login_location']) && !empty($_POST['login_location'])) ) {
add_filter('login_redirect', 'my_login_redirect', 10, 3);
function my_login_redirect() {
$location = $_SERVER['HTTP_REFERER'];
wp_safe_redirect($location);
exit();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.