Hide a page if a user is not logged in

Sometimes you might want to hide a page if a user is not logged in. To do this you can use this simple snippet to call a page from within your theme folder called ‘not-logged-in.php’ but, remember this will call before the header, footer and the bits in between so the file that is called should contain the whole code for the page including the html, head and body; opening and closing tags.

/* Template Name: Only for logged in users */
if ( !is_user_logged_in()) {

the file that’s called might be something like this:

<title>Ooops! You need to login.</title>
<h1>To view this page you need to login.</h1>

source: Developing a WordPress site on a live url


A geek who likes to cook with wp ingredients!

Leave a Reply

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