This is driving me nuts, and I'm sure that as soon as someone points out the answer, I'm going to feel dumb.
I have a website where most pages require login to view. So I am using an if statement to view page content if a user is logged in, or view a login form if not.
If I put this in a page template, everything works just fine:
<?php get_header(); ?> <?php if(is_user_logged_in()): ?> <div id="wrapper"> <h5><?php the_field('headline'); ?></h5> <?php the_field('text'); ?> </div> <?php else: $args = array( 'pagename' => 'request-access' ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); the_content(); endwhile; endif; wp_reset_postdata(); endif; ?> <?php get_footer(); ?>
That's great, but it makes more sense to put the if statement in the header so I don't have to copy it onto every single page template. But if I put the exact same if statement:
<?php if(is_user_logged_in()): ?>
at the end of the header.php, I get an error saying "Parse error: syntax error, unexpected $end" in the last line of header.php. So why does this work at the beginning of a template file but not at the end of the header file?