title: User is logged out when refreshing page
body: <p>I am having issues with a Wordpress members site. The install is multisite with subdomains.</p>
  
  <p>I require the user to be logged in to view all pages of the subdomain site. To do this I have opted against any functions and placed <code>&lt;?php wp_login_form(); ?&gt;</code> within the <code>page-template</code> as shown here...</p>
  
  <pre><code>&lt;?php if ( is_user_logged_in() ) {
  get_header(); ?&gt;
     &lt;div class="page-content-wrapper "&gt;
     &lt;/div&gt;
  &lt;?php get_footer();?&gt;
  
  &lt;?php } else {?&gt;
  &lt;?php get_header('login'); ?&gt;
  &lt;?php wp_login_form(); ?&gt;
  &lt;?php get_footer('login');?&gt;
  &lt;?php }?&gt;
  </code></pre>
  
  <p>This works a charm - when a <code>is_user_logged_in()</code> they get the page and when not they get <code>wp_login_form();</code>. My issue arises when leaving this page. The user is logged out and upon returning to the page has to login again as shown here. </p>
  
  <p><a href="https://i.stack.imgur.com/273kG.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/273kG.gif" alt="Login error"></a></p>
  
  <p>This also happens when I add <code>if ( is_user_logged_in() )</code> to other pages.</p>
  
  <p>I have also tried a redirect to <code>wp-login.php</code> when a user is required to login but this does the just loops back to <code>wp-login.php</code> which suggests to me that I am having a cookie issue as the login credentials logged.  </p>
  
  <p>I have noticed that before login the cookies are shown as shown</p>
  
  <p><a href="https://i.stack.imgur.com/3J12h.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3J12h.gif" alt="Cookies before login"></a></p>
  
  <p>and after login they show as shown</p>
  
  <p><a href="https://i.stack.imgur.com/wdPgo.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wdPgo.gif" alt="Cookies after login"></a></p>
  
  <p>Upon revisiting the page that requires login the cookies revert to the original. However, user credentials are never stored. </p>
  
  <p>Any help would be appreciated. </p>
  
  <p><strong>UPDATE</strong> 
  It appears that if I first log into <code>wp-admin</code> I can visit the page and the user information is displayed. If I leave the page the user is logged out and a login is required.  </p>