Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP Add WordPress Login Form On Sidebar Or Custom Page

Add WordPress Login Form On Sidebar Or Custom Page

By default, you only can login to your Dashboard by clicking on Login link in Meta panel or go direct to login link such as: http://4rapiddev.com/wp-login.php. This tutorial will show you how to create and add the login form everywhere you want. For example, it could be on your homepage, sidebar or even on a custom page.

Simply copy & paste the following code below to display your login form. It will create a login form which includes Username & Password text box, Remember me check box, Login button and Forgot password link.

1. Add the login form on Sidebar

Open your sidebar.php file located in your theme directory and add code below:

<li>
<?php 
	if(!is_user_logged_in())
	{
?>        
<form name="login" method="post" action="<?php echo get_option('home'); ?>/wp-login.php">
	<input type="hidden" name="action" value="login" />
	<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
	<table width="50%" border="0" cellpadding="0" cellspacing="0">
	  <tr>
		<td style="padding-bottom: 8px;"><strong>MEMBER LOGIN</strong></td>
	  </tr>
	  <tr>
		<td><strong>Username: </strong><br /><input type="text" name="log" id="log" value="" class="text" /></td>
	  </tr>
	  <tr>
		<td><strong>Password:</strong><br /><input type="password" name="pwd" id="pwd" class="text" style="width: 150px;" /></td>
	  </tr>
	  <tr>
		<td><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</td>
	  </tr>
	  <tr>
		<td align="left" valign="top"><input type="submit" value="Login"/></td>
	  </tr>
	  <tr>
		<td align="left" valign="top"><a href="<?php echo get_option('home'); ?>/forgot-password/">[Forgot password?]</a> </td>
	  </tr>
 
	</table>
</form>
<?php 
	}
	else
	{
		global $current_user;
		get_currentuserinfo();
		if($current_user->user_firstname != '' && $current_user->user_lastname)
			echo "Welcome " . $current_user->user_firstname . "," . $current_user->user_lastname . "!";
		else
			echo "Welcome " . $current_user->user_login . "!";
 
		echo " | <a title='Logout' href='" . wp_logout_url('index.php') . "'>Logout</a><br><br>"; 
?>
          You are currently logged in!
<?php 
	}
?>			
			</li>

<li> <?php if(!is_user_logged_in()) { ?> <form name="login" method="post" action="<?php echo get_option('home'); ?>/wp-login.php"> <input type="hidden" name="action" value="login" /> <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" /> <table width="50%" border="0" cellpadding="0" cellspacing="0"> <tr> <td style="padding-bottom: 8px;"><strong>MEMBER LOGIN</strong></td> </tr> <tr> <td><strong>Username: </strong><br /><input type="text" name="log" id="log" value="" class="text" /></td> </tr> <tr> <td><strong>Password:</strong><br /><input type="password" name="pwd" id="pwd" class="text" style="width: 150px;" /></td> </tr> <tr> <td><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</td> </tr> <tr> <td align="left" valign="top"><input type="submit" value="Login"/></td> </tr> <tr> <td align="left" valign="top"><a href="<?php echo get_option('home'); ?>/forgot-password/">[Forgot password?]</a> </td> </tr> </table> </form> <?php } else { global $current_user; get_currentuserinfo(); if($current_user->user_firstname != '' && $current_user->user_lastname) echo "Welcome " . $current_user->user_firstname . "," . $current_user->user_lastname . "!"; else echo "Welcome " . $current_user->user_login . "!"; echo " | <a title='Logout' href='" . wp_logout_url('index.php') . "'>Logout</a><br><br>"; ?> You are currently logged in! <?php } ?> </li>

WordPress Login Form on Sidebar

WordPress Login Form on Sidebar

2. Add login form on a Custom template page

As I mentioned above, you even can put the login form on a custom page. To do that, open your page.php file in your Theme directory or create a new page based on a new custom WordPress template page then add the code below:

<?php 
	if(!is_user_logged_in())
	{
?>        
<form name="login" method="post" action="<?php echo get_option('home'); ?>/wp-login.php">
	<input type="hidden" name="action" value="login" />
	<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
	<table width="450px" border="0" cellpadding="0" cellspacing="0">
	  <tr>
		<td colspan="2" style="padding-bottom: 8px;"><strong>MEMBER LOGIN</strong></td>
	  </tr>
	  <tr>
		<td><strong>Username:</strong></td>
		<td align="right"><input type="text" name="log" id="log" value="" class="text" /></td>
	  </tr>
	  <tr>
		<td><strong>Password:</strong></td>
		<td align="right"><input type="password" name="pwd" id="pwd" class="text" /></td>
	  </tr>
	  <tr>
		<td align="left" colspan="2"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</td>
	  </tr>
	  <tr>
		<td align="left" colspan="2"><input type="submit" value="Login"/></td>
	  </tr>
	  <tr>
		<td align="left" colspan="2"><a href="<?php echo get_option('home'); ?>/forgot-password/">[Forgot password?]</a> </td>
	  </tr>
 
	</table>
</form>
<?php 
	}
	else
	{
		global $current_user;
		get_currentuserinfo();
		if($current_user->user_firstname != '' && $current_user->user_lastname)
			echo "Welcome " . $current_user->user_firstname . "," . $current_user->user_lastname . "!";
		else
			echo "Welcome " . $current_user->user_login . "!";
 
		echo " | <a title='Logout' href='" . wp_logout_url('index.php') . "'>Logout</a><br><br>"; 
?>
          You are currently logged in!
<?php 
	}
?>

<?php if(!is_user_logged_in()) { ?> <form name="login" method="post" action="<?php echo get_option('home'); ?>/wp-login.php"> <input type="hidden" name="action" value="login" /> <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" /> <table width="450px" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="2" style="padding-bottom: 8px;"><strong>MEMBER LOGIN</strong></td> </tr> <tr> <td><strong>Username:</strong></td> <td align="right"><input type="text" name="log" id="log" value="" class="text" /></td> </tr> <tr> <td><strong>Password:</strong></td> <td align="right"><input type="password" name="pwd" id="pwd" class="text" /></td> </tr> <tr> <td align="left" colspan="2"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</td> </tr> <tr> <td align="left" colspan="2"><input type="submit" value="Login"/></td> </tr> <tr> <td align="left" colspan="2"><a href="<?php echo get_option('home'); ?>/forgot-password/">[Forgot password?]</a> </td> </tr> </table> </form> <?php } else { global $current_user; get_currentuserinfo(); if($current_user->user_firstname != '' && $current_user->user_lastname) echo "Welcome " . $current_user->user_firstname . "," . $current_user->user_lastname . "!"; else echo "Welcome " . $current_user->user_login . "!"; echo " | <a title='Logout' href='" . wp_logout_url('index.php') . "'>Logout</a><br><br>"; ?> You are currently logged in! <?php } ?>

WordPress Login Form On Custom Page

WordPress Login Form On Custom Page

Download the sidebar.php file or page-login.php custom WordPress page template file which contains the login form.

May 29, 2011Hoan Huynh
Create A New Template For WordPress PageAdd More Extra Informations Or Fields To WordPress User Profile
You Might Also Like:
  • Show Error Message On WordPress Custom Login Template Page
  • Create Custom Update Profile Page For WordPress Users
  • Disable Auto Save Password In HTML Form Or TextBox
  • Create A New Template For WordPress Page
  • How to create new custom menu item in your wordpress back end?
  • PHP Login Or Sign In With Google Account By OpenID
  • How To Change Default Home Page Of WordPress
  • Add And Get Custom Field In WordPress
  • A handy guideline on adding custom menu item in WordPress admin
  • Add More Extra Informations Or Fields To WordPress User Profile
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

9 years ago PHPget_currentuserinfo, get_option, How To, is_user_logged_in, Wordpress, wp_logout_url208
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
21,918 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
19,746 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,583 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,094 views
C# Read Json From URL And Parse/Deserialize Json
9,557 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Research Paper Writing Service
  • Annotated Bibliography Example – How it Can Help You
  • Essay Writing Online Tips – How to Write Essays Online With Essay Proof Editing
  • Get Research Paper Assistance From Professional Help
  • Customized Essay Writing Agency – Why You Want It
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (28)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (62)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development