0

Hello, I have this code so when I place the [need_login] shortcode on a page, it redirects users who are not logged in to a Login page. The problem with this is the that it redirects them to the default WordPress page. How can I add the url of the page I want them to be redirected to.


function shortcode_needLogin() {
    if (!is_user_logged_in()) {
        auth_redirect();
    }
}

2 Answers 2

0

Use wp_redirect() instead of auth_redirect() - make sure to call exit() right after wp_redirect(). Check out the codex for more info on wp_redirect.

0

Great question. As ScottM mentioned, you want to use wp_redirect() rather than auth_redirect. Then within the (), you'll want to specify your target.

It always makes the most sense to me when I can see real code, so I'd encourage you to look at Redirect user to original url after login? - there are multiple methods / code options, each shown there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.