Support » Developing with WordPress » Hide/Remove Header on protected page

  • Hey everybody,

    I have a question, i hope someone can help me!

    I would like to have the possibility of having a HEADER not visible on all protected pages.
    Like you can see, I customized the protected page at the address below.

    Link: http://builder.depretz.com/artist-painter-site-one-page

    Password: [readacted]

    for backoffice acces go to http://builder.depretz.com/wp-admin

    [redacted]

    Like you see the HEADER is visible on the protected page. I want to hide it for all the pages if they are protected and show just the CONTENT area.
    When you put the password and access to the full page, I want to display the HEADER on it.

    I use Beaver Builder for building the pages.

    what kind of code I need to add on functions.php or is it a plugin for doing this?

    Thank you

    [Note: Anything you put in a forum topic or a pastebin is public. Anybody can see it. Don’t post any passwords or private info there.]

    • This topic was modified 3 years, 1 month ago by Steve Stern.
    • This topic was modified 3 years, 1 month ago by Steve Stern.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    This would only be feasible on single post pages because otherwise WP cannot tell if something is protected or not because there are multiple posts on the page. There needs to be only a single post (or page post type) for accurate determination. Because the header content is outside the loop, the first thing to do is get the current WP_Post object with $post = get_queried_object();. Be sure you really got a post object with $post instanceof WP_Post being true. If so it’s safe to check if a password is required with post_password_required( $post )

    If a password is NOT required then it’s safe to output the normal header or whatever else you normally suppress with passwords. If a password is required, output nothing, except one time somewhere on the page you want to do the following instead: echo get_the_password_form( $post );

    The post_password_required() check can be done multiple times on the various templates and parts that make up a single page or post output. The password form is output only once. Be sure you at least output enough to make up a valid HTML page at all times regardless of password requirement. Make sure all tag output is properly balanced. If a div tag is suppressed in one place, be sure it’s matching closing tag is also suppressed.

    Thanks for your answer, but i did not understand everything

    Can you make a demo for me I can give you my access?

    Moderator bcworkz

    (@bcworkz)

    Please never give anyone in these forums privileged access to your site. It can be a risky proposition for both parties, thus it is simply not allowed at all by this forum’s rules.

    A basic template might look something like this (untested):

    $post = get_queried_object(); // do first, only needed once
    // do the following as needed to hide sections of protected content
    if ( $post instanceof WP_Post && post_password_required( $post )) {
       // do nothing, except one time on the page do this:
       echo get_the_password_form( $post );
    } else {
       // content to be hidden when password is required
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide/Remove Header on protected page’ is closed to new replies.