Redirect to login page in wordpress
<p>I am new to wordpress. I am running wordpress setup on <code>http://localhost/wordpress/</code>. I am facing two problems right now:</p>

<ul>
<li>Only the logged in users can access the site. So, I am trying to redirect the user from home page to login page using the following code which is somehow isn't working:</li>
</ul>

<blockquote>
  <p>Path: <code>wp-content/themes/twentysixteen/header.php</code></p>
</blockquote>

<pre><code>        &lt;?php
            if(get_permalink() != wp_login_url() &amp;&amp; !is_user_logged_in()){
                wp_redirect( wp_login_url() ); exit;
            }
        ?&gt;
</code></pre>

<p>Since the above code wasn't working, I tried to move on by letting the user to login manually by clicking on the <code>login</code> button. Here is the working code:</p>

<pre><code>&lt;?php
    if(get_permalink() != wp_login_url() &amp;&amp; !is_user_logged_in()){
        // wp_redirect( wp_login_url() ); exit;
?&gt;
        &lt;a href="&lt;?php echo wp_login_url( get_permalink() ); ?&gt;" title="Login"&gt;Login&lt;/a&gt;
&lt;?php
    }
?&gt;
</code></pre>

<ul>
<li>From above code, when user clicked on login  he was redirected to login page and When the user is logs in, the page is redirecting to wordpress admin i.e <code>wp-admin</code> instead of home page i.e <code>http://localhost/wordpress</code>.</li>
</ul>

<h3>What I am trying to do is:</h3>

<ul>
<li>Redirect the user from home page to login page, if the user isn't logged in.</li>
<li>And then redirect the user from login page to home page instead of wp-admin, when user logs in.</li>
</ul>