wordpress account creation referrer page code example
Example: wordpress account creation referrer page
function redirect_user_tologin(){
global $post;
$post_slug = $post->post_name;
if(!is_user_logged_in()){
if($post_slug == 'my-account') { //can add multiple conditions
//create dynamic redirect page link
$redirect = urlencode(site_url().'/'.$post_slug);
//redirection
wp_safe_redirect(site_url().'/wp-login.php/?redirect_to=' .$redirect);
exit;
}
}
}
add_action('wp', 'redirect_to_login');