0

i completed my website but i want to protect my site using login option.when i enter my site its goes to login page if user logged in after home page will display.how can do that if there any plugin..... But temporaly i put below code in front-page.php. login option will display overlay of my front page. but its not a correct way. if logged in .logged-in .login_page{display:none;}

if i logout #loggedout .login_page{display:block;} in below code " title="Logout">Logout

 <div class="login_page">
  <div class="loginInfo">
    <?php if (!(current_user_can('level_0'))){ ?>
    <form action="<?php echo get_option('home'); ?>/wp-login.php" method="post">
      <div class="userIndex">
        <input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="20" />
      </div>
      <div class="pwdIndex">
        <input class='pwd' type="password" name="pwd" id="pwd" size="20" />
      </div>
      <div class="submitIndex">
        <input type="submit" name="submit" value="Send" class="button" />
      </div>      
      <p style="display:none">
        <label for="rememberme">
          <input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" />
          Remember me</label>
        <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
      </p>
    </form>
    <a style="display:none" href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword">Recover password</a>
    <?php } else { ?>
    <a style="display:none" href="<?php echo wp_logout_url(urlencode($_SERVER['REQUEST_URI'])); ?>" id="logoutin">logout</a><br />
  <?php }?>
</div>
</div>
0

In the header.php of your theme you can add the following code @ the beginning of the php code

if ( is_user_logged_in() ) {
  header( 'Location: /' );
} else {
  header( 'Location: /wp-login.php' );
}

If the user is not logged it will be redirected to the login form else it will be redirected to the /home page or tha page u want.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.