title: Wordpress auto login from custom page
body: <p>In my wordpress website I have created a custom registration page to register in Wordpress using "PHP Code" plugin. Now I wanted to auto login the users when they complete the registration. I did lot of research but couldn't find a solution for my problem. I tried the following sample snippet to test in the custom page :</p>
  
  <pre><code>&lt;?php
  
  //Log in a WordPress user programmatically
  function auto_login( $user ) {
      $username   = $user;
      if ( !is_user_logged_in() ) {
          $user = get_user_by('login', $username );
          $user_id = $user-&gt;ID;
          wp_set_current_user( $user_id, $user_login );
          wp_set_auth_cookie( $user_id );
          do_action( 'wp_login', $user_login );
      }     
  }
  
  auto_login('admin');
  
  ?&gt;
  </code></pre>
  
  <p>But I am getting following errors.</p>
  
  <pre><code>Warning: Cannot modify header information - headers already sent by (output started at /home/content/19/11054119/html/wp-content/plugins/sitepress-multilingual-cms/inc/language-switcher.php:921) in /home/content/19/11054119/html/wp-includes/pluggable.php on line 925
  
  Warning: Cannot modify header information - headers already sent by (output started at /home/content/19/11054119/html/wp-content/plugins/sitepress-multilingual-cms/inc/language-switcher.php:921) in /home/content/19/11054119/html/wp-includes/pluggable.php on line 926
  
  Warning: Cannot modify header information - headers already sent by (output started at /home/content/19/11054119/html/wp-content/plugins/sitepress-multilingual-cms/inc/language-switcher.php:921) in /home/content/19/11054119/html/wp-includes/pluggable.php on line 927
  </code></pre>
  
  <p>So I am wondering is there anyway to do auto login without touching the theme functions. If you have any idea or solution help me with this..</p>
  
  <p>Thanks</p>