Site icon Hip-Hop Website Design and Development

Redirect unloggedin users

I added the following code via the cPanel to the function.php file.

    add_action('template_redirect','woo_check_loggedin');

function woo_check_loggedin(){
   // this condition checks for certian pages

      // if user is not logged in we redirect him to login page you can also show error message instead of redirect if that the requirment.
      if(!is_user_logged_in() && !is_page(lost-password) ){
          wp_redirect("https://example.com/wp-login.php");
          exit;
      }
      

   }

But, when I now go e.g. to mysite.com/shop it still works (I can visit every site). How can I avoid that? Because the site should only be avaiable for loggedin users. (But only the admin can create Logins).