DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

WordPress allows you to make a post private, but what about static pages? Here’s a quick, clear and concise recipe to create a private page template.

If you want to make all your blog pages private, you can use the code “as it”, but I recommend you to create a page template, so you can decide if the page is public or private when you’ll write it in your WordPress dashboard.

If you don’t know how to create and use page templates, read this recipe first.

To check if the current reader is authenticated or not, WordPress provide the is_user_logged_in() function, which will return true if user is logged in, false otherwise.

We just have to create a basic php conditional instruction and check if the user is logged in:

if (is_user_logged_in()) {
// You page code goes here
} else {
echo "You must be logged in to view this page.";

Insert the code above in a new page template. When you’ll want to make a private page, just use this template.


  1. Climbing the steep learning curve here… Tried to make a page private with the code you list above, then realized I had another way. Now I can’t seem to get rid of the code – it is listed at the bottom of all my pages. Help!

    Thank you.

  2. Hi again. Sorry to bug you… looking all over the wordpress forums for the answer and still perplexed. The code doesn’t show in the dashboard – text or HTML, so I’m uncertain how to remove. It appears at the bottom of all my (static) pages – and looks quite odd and unprofessional. Please help!

    Thanks so much.

  3. Hi Callie – just came across this post. I know this post is almost a year old, but if you still haven’t found the answer, you need to enclose that code with a php call so it looks like this:

Leave a Comment

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