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 class="pwdIndex">
        <input class='pwd' type="password" name="pwd" id="pwd" size="20" />
      <div class="submitIndex">
        <input type="submit" name="submit" value="Send" class="button" />
      <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']; ?>" />
    <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 }?>

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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