I created a drop down menu under My Account, like order, account info, address...etc, how can I just redirect all visitor to login page if they are not login?


Just make sure auth_redirect() is executed for the user on the desired pages (before any content is printed).

There are many ways to do this. You can add something like this to functions.php

$pages_auth_check = [ 25, 40, 55 ]; // IDs of the pages to check.
$current_page     = get_the_ID();

if ( in_array( $current_page, $pages_auth_check ) ) {

So the auth_redirect() will be executed only for the pages with the specified IDs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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