How to redirect non-logged in users to a specific page?

EncodeMore

Do you need it on home/front page only? If so, try this:

add_action( 'template_redirect', function() {
    if ( is_front_page() &&  !is_user_logged_in() ) {
        wp_redirect( home_url( '/presentation' ) );
        die();
    }
} );

If you want ALL pages to WordPress’s default login page

add_action( 'template_redirect', function() {
    if ( !is_user_logged_in() ) {
        auth_redirect();
    }
} );

Share This Article
Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *