was successfully added to your cart.


How to Redirect User If They Are Not Logged In (WordPress)

By December 11, 2016 December 26th, 2018 Webite

“How to redirect user if they are not logged in” is a WordPress question that is commonly asked and is something that is very easy to do without using a plugin
Redirecting a user if they are not logged in is ideal for private and membership sites as you can redirect the user to a specific page (a sales page for example) if they are not logged in.

I personally use this trick on my subdomain training.peterstavrou.com which is a demo site I setup for my YouTube training videos.


How To Redirect User If Not Logged In

To achieve this you simply need to add a piece of code in your header.php file.

  1. 1. Login to the back-end of your WordPress site and go to Appearance then Editor.
  2. How To Redirect User If Not Logged In


  3. 2. On the left-hand side, under Templates click on header.php

  5. 3. Copy and paste the below code at the very top, just under ?php
if (!is_user_logged_in()) {
wp_redirect( 'https://www.peterstavrou.com');
} ?>


For Example:

How To Redirect User If Not Logged In

4. Change the URL https://www.peterstavrou.com to a URL of your choice and click on the Update File button.

That’s all there is to it 🙂


Leave a Reply to Sam Cancel Reply


Do NOT follow this link or you will be banned from the site!