Home Tutorials How to place a login form in the sidebar

How to place a login form in the sidebar

Author

Date

Updated on

Category

Skip the login page. Want to log in through the front page? If yes then this tutorial is perfect for you. First, let’s see how it actually looks like. I tested it with my Lust WordPress theme on two local WordPress installs, version 2.1 and 2.2.

Here’s the login form in the sidebar:

sidebar_login

Here’s the message after you’ve logged in:

admin_logged

And here’s what a logged in subscriber would see:

user_logged

So how do you put a login form in the sidebar? Simple, I did the work for you. Copy and paste the below code in sidebar_login.txt to your sidebar. The URLs generated by this code is compatible with WordPress version 2.1 and up only. 2.0 and earlier versions are not compatible.

<?php global $user_ID, $user_identity, $user_level ?>
		<?php if ( $user_ID ) : ?>
		<h2>Control panel</h2>
		<ul>
			<li>Identified as <strong><?php echo $user_identity ?></strong>.
			<ul>
				<li><a href="<?php bloginfo('url') ?>/wp-admin/">Dashboard</a></li>

				<?php if ( $user_level >= 1 ) : ?&gt;
				<li><a href="<?php bloginfo('url') ?>/wp-admin/post-new.php">Write an article</a></li>
				<?php endif // $user_level >= 1 ?&gt;

				<li><a href="<?php bloginfo('url') ?>/wp-admin/profile.php">Profile and personal options</a></li>
				<li><a href="<?php bloginfo('url') ?>/wp-login.php?action=logout&amp;redirect_to=<?php echo urlencode($_SERVER['REQUEST_URI']) ?>">Exit</a></li>
			</ul>
			</li>
		</ul>

		<?php elseif ( get_option('users_can_register') ) : ?>

		<h2>Identification</h2>
		<ul>
			<li>
			<form action="<?php bloginfo('url') ?>/wp-login.php" method="post">
				<p>
				<label for="log"><input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="22"/> User</label><br/>
				<label for="pwd"><input type="password" name="pwd" id="pwd" size="22"/> Password</label><br/>
				<input type="submit" name="submit" value="Send" class="button"/>
				<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever"/> Remember me</label><br/>
				</p>
				<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/>
			</form>
			</li>

			<li><a href="<?php bloginfo('url') ?>/wp-register.php">Register</a></li>
			<li><a href="<?php bloginfo('url') ?>/wp-login.php?action=lostpassword">Recover password</a></li>
		</ul>

		<?php endif // get_option('users_can_register') ?>

	</li>

This technique is especially useful if you’re tired of having to go to the login page or if your blog place great importance on getting readers to register for accounts and actually log in.

SourceThe original code was from MW WordPress theme by Javier García. I restructured and modified the code for a WordPress-like sidebar structure and valid XHTML.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent posts

Flat Design for Your WordPress Site: What Is It + 4 WordPress Flat Design Themes

Web designers in the past mostly used 3D styles for buttons that made the button seem more realistic. That all changed when flat design...

LawBlog WP Theme Review

Regardless of which area of law you practice, it’s imperative that you have proper online representation. You need to give your customers a feeling...

The Deeper Meaning and Purpose Behind Shapes in Web & Graphic Design

Sometimes in web design, a clean website is often the best choice for certain clients. Instead of elaborate backgrounds or too many aesthetic choices,...

How to Easily Design a Website Without Coding

Are you looking to build a website and you don’t know how to code? Online web design services are helpful to create website templates...

The importance of SSL Certificates as part of a web hosting package

Building a successful business requires trust, and gaining trust can be difficult especially when you run a business where it is taken for granted...

Recent comments