Re-Direct ALL Users to the Home Page IF not logged in


I just read the codex on wp_redirect(); and found an example that I modified. Problem is, all I get is an error in my browser saying "The page isn’t redirecting properly".

I need all users, unless logged in, to be re-directed to the home page (home_url()).

Can someone please help me?

add_action( 'template_redirect', 'not_logged_in_redirect_home' );
add_action( 'do_feed', 'not_logged_in_redirect_home' );
function not_logged_in_redirect_home() {

        if ( is_home() ) return;

        if ( ! is_user_logged_in() && is_home() ) return;

        if ( ! is_user_logged_in() && !is_home() ) {
            wp_redirect( home_url() );
Harold Aldersen 3 weeks 0 Answers 3 views 0

Leave an answer