This website uses cookies to allow us to see how the site is used. If you continue to use this site, we assume that you are okay with this. If you want to use the sites without cookies, please see our privacy policy.

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 code and be nice ^_^

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.