Support

Is is possible to make a page on WordPress only viewable to logged in members?

Our Support Desk is where our clients and community come together to find solutions.

Answered
0
0

We would like to make one of the pages on our site, which contains a Gravity Form, only viewable to logged in users – how can that be done?

  • You must to post comments
Best Answer
0
0

I’ve added a very simple page template to the active theme – which includes a check to see if the user is logged in – here is the code:

<?php 

/*
Template Name: Logged in Only    
*/

get_header(); 

global $gp_settings; 

// only run for logged in users ##
if ( is_user_logged_in() ) {

    $access_granted = true;

}

if ( have_posts() ) {

    while ( have_posts() ) {

        // set-up post data ##
       the_post(); 

?>
<div id="content" role="main">
    <div class="padder">
        <h1 class="page-title"><?php the_title(); ?></h1>           
    <?php if ( $access_granted === true ) : ?>

            <?php the_content(); ?>          

        <?php else : ?>

            <p><?php _e('You need to be logged in to view this page.'); ?></p>

    <?php endif; ?>
    </div>
</div>
<?php 

    } // while - have_posts ##

} // have_posts ## 

get_footer();

Now you can select the template called “Logged in Only” to be able to block non-logged in viewers from seeing the content of a specific page.

  • Nelly
    Thanks!!!
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Why not Search Our Work or Get in Touch