Title: Conditional statement for password protected posts
Last modified: August 19, 2016

---

# Conditional statement for password protected posts

 *  [chazVnG](https://wordpress.org/support/users/chazvng/)
 * (@chazvng)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/conditional-statement-for-password-protected-posts/)
 * In a nutshell, I’m wondering if there’s a conditional statement for when a post
   is password protected. Something like: is_post_logged_in() or similar.
 * Here’s why:
 * I’ve built our company’s website, but I have an estimator that we don’t want 
   to be public for our website. Since it is a php and javascript based estimator,
   I needed to use the header and the body to make it run, so I had to create different
   templates for both the header and the body pages. Because of this and other reasons,
   I didn’t want to put the body in the post area of that page in wordpress, so 
   I basically have a blank post and all the content lives inside the actual template
   file.
 * Right now I’ve got it using the must be logged in to view the page system, but
   we definitely don’t want to give our clients access to our entire backend.
 * So it seems it would be easier if I could just wrap all that code in a conditional
   statement for that password protected page. Did that all make sense?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Mark Ratledge](https://wordpress.org/support/users/songdogtech/)
 * (@songdogtech)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/conditional-statement-for-password-protected-posts/#post-1692684)
 * [http://wordpress.org/extend/plugins/role-scoper/](http://wordpress.org/extend/plugins/role-scoper/)
 *  [David Sader](https://wordpress.org/support/users/dsader/)
 * (@dsader)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/conditional-statement-for-password-protected-posts/#post-1692708)
 * If you want something to appear in your template(ie header or footer) only if
   password has been entered for a protected post:
 *     ```
       <?php
       if ( post_password_required($post) ) {
          //do some stuff if no password has been cookied such as
       	$output = get_the_password_form();
       	echo $output;
           } else {
         // show the stuff that required the password
       }
       ?>
       ```
   
 *  Thread Starter [chazVnG](https://wordpress.org/support/users/chazvng/)
 * (@chazvng)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/conditional-statement-for-password-protected-posts/#post-1693002)
 * Songdogtech, Initially I wasn’t looking at a role manager, but this might actually
   make sense for another section of the website. If I go this route, is there a
   way to make the login pieces show up on that page and when you login go RIGHT
   to that specific page and not the dashboard?
 * David, I tried that code, and it didn’t work. I’m not a php expert, am I missing
   something?
 *  Thread Starter [chazVnG](https://wordpress.org/support/users/chazvng/)
 * (@chazvng)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/conditional-statement-for-password-protected-posts/#post-1693003)
 * Also, if I make the parent page password-protected, it seems like the children
   are not password-protected. So that a visitor only has to put the password in
   once, is there something I need to put in the template file for those specific
   pages that makes the children also protected under the same password?
 * Thanks for the help guys.
 *  [David Sader](https://wordpress.org/support/users/dsader/)
 * (@dsader)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/conditional-statement-for-password-protected-posts/#post-1693018)
 * You need to massage my snippet above into a loop. or add
 * `global $post; // if outside the loop`
 * [http://codex.wordpress.org/Conditional_Tags](http://codex.wordpress.org/Conditional_Tags)
 * Anyway, I think you have to set up each page with its own password, regardless
   of whether it is parent or sub page. Parent page password protection does not
   extend to child pages. You are going to get a separate cookie for each page/password
   combination. You will need to edit every post/page that needs a password if you
   are expecting it to be protected via post/page password. Then you will be entering
   a password when first viewing each page.
 *  [chazthetic](https://wordpress.org/support/users/chazthetic/)
 * (@chazthetic)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/conditional-statement-for-password-protected-posts/#post-1693039)
 * Alright, so I’ve been thinking about the logged-in vs. password protected personal
   debate, and I think for this whole section of the website since it’s a series
   of several pages, it makes sense for the users to be logged in.
 * I’d like to put a login box on the page if you’re not logged in, and then have
   it load the page when you log in, not redirect to the admin. Is there an easier
   way to do this than I’m finding online? I’ve found resources for changing the
   wp-login page, but I want to be able to code it into those page template files.
 *  Thread Starter [chazVnG](https://wordpress.org/support/users/chazvng/)
 * (@chazvng)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/conditional-statement-for-password-protected-posts/#post-1693040)
 * Alright, so I’ve been thinking about the logged-in vs. password protected personal
   debate, and I think for this whole section of the website since it’s a series
   of several pages, it makes sense for the users to be logged in.
 * I’d like to put a login box on the page if you’re not logged in, and then have
   it load the page when you log in, not redirect to the admin. Is there an easier
   way to do this than I’m finding online? I’ve found resources for changing the
   wp-login page, but I want to be able to code it into those page template files.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Conditional statement for password protected posts’ is closed to new 
replies.

## Tags

 * [password](https://wordpress.org/support/topic-tag/password/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [protected post](https://wordpress.org/support/topic-tag/protected-post/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 4 participants
 * Last reply from: [chazVnG](https://wordpress.org/support/users/chazvng/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/conditional-statement-for-password-protected-posts/#post-1693040)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
