Have you ever thought to add a login panel to your site? I worked on one lately for a site with multiple contributors. With WordPress it is a simple task, that you might want to do, if you want your visitors to sign in for any reason.
Instead of having your visitors go to the WordPress login panel, you can save them the extra click by presenting a login form in the home page of your site.
This is a great way to manage your site, if you allow only signed in users to comment or post, or if you want to add subscriber only content, or material that only subscribers can download from your site.
In the sidebar of you site you can just add the following html form code to accept user id and password.
Edit sidebar.php file under your theme. Just pick an area where you want to add the form by adding the following code after any </li> tag depending on where you want to display the form. Ideally you want to display it at the top of your sidebar.
<li>
<?php if (is_user_logged_in()){
echo “<h2>Welcome! </h2>”; ?><ul>
<li><a href=”<?php echo wp_logout_url(get_permalink()); ?>”>Logout</a></li>
</ul>
<?php } else { ?><form name=”loginform” id=”login” action=”<?php echo get_settings(’siteurl’); ?>/wp-login.php” method=”post”>
<h2>Account Login</h2>
<label for=”userid”>Userid:</label>
<input type=”text” name=”log” value=”" id=”userid” size=”15″/><br />
<label for=”password”>Password:</label>
<input type=”password” name=”pwd” value=”" id=”password” size=”10″/>
<input type=”submit” name=”submit” value=”Login” id=”enter” />
<p><?php wp_register(”, ”); ?>
<p><a href=”<?php bloginfo(’wpurl’); ?>/wp-login.php?action=lostpassword”>Lost your password?</a></p>
</form><?php } ?>
</li>
This above php/html will do a basic form where:
<?php if (is_user_logged_in()){
Checks if anyone is logged in, then prints “Welcome registered user”and displays a link to log out, else if no one is logged in, it displays the login form.
This is a basic html form where:
<h2>Account Login</h2>
is the title of the form
<label for=”userid”>Userid:</label>
to assigns an informative label.
<input type=”text” name=”log” value=”" id=”userid” size=”15″/><br />
text box to accept user input to a text field. Note: Here you can add the optional size argument to any size that fits your sidebar area.
There are about 10 specific types to the <input /> tag. In any simple login form you will need to use 3.
1-text: for entering text. 2-password: to enter a password, and 3- submit: which creates a submit button.
<p><?php wp_register(”,”); ?>
you might want to add this line if you want to allow your visitors to register.
Let me know, if you have any questions about it.
Regards.
Popularity: 51% [?]
13 Responses
Brian N. Hewlett, M.A., Ph.D.
April 23rd, 2009 at 12:30 am
1I pasted your script as you suggested and it does not seem to work.
Sherif
April 23rd, 2009 at 5:31 am
2oops, sorry Brian, I noticed when pasting the code, the stylesheet changes the quotes ” and this is failing. I will email you the html and hope it will work.
I will also find out how to fix the stylesheet issue.
Regards.
Edward.H
April 23rd, 2009 at 5:42 am
3thanks for your useful article ,I have submitted a link of this article to our webiste http://www.webmasterclip.com in order to share it with more people.
Sherif
April 23rd, 2009 at 6:26 am
4Thank you Edward, I like your site webmasterclip.com. It provides good value.
priyanka
May 19th, 2009 at 8:02 am
5Grea8
Thanx for this Way
I really need this in urgent ….
thanx again
V.C
June 11th, 2009 at 6:01 am
6I was wondering If you could show me how to display a log in link on the head of page.
V.C’s last blog post..Links for 2009-06-10 [Digg]
Sherif
June 11th, 2009 at 7:13 am
7Sure, you can do something like this:
< ?php if (!is_user_logged_in()){ ?> // if visitor not logged in
href=”< ?php bloginfo('wpurl'); ?>/wp-login.php”>Login” // need to add the anchor tag here
< ?php } ?>
V.C
June 17th, 2009 at 3:52 pm
8Thank you very much !
So if after logging in, could my users see the log out link?
V.C’s last blog post..Video: Skinny Jeans Style Tip
wolfegod
June 26th, 2009 at 4:46 pm
9thanks, very informative will try soon.
Juergen Sober
July 31st, 2009 at 2:44 pm
10That sounds very interesting. As soon as I have some spare time (for debugguing
) I’ll take the risk and try your proposal. Up to now I didn’t ever touch the blogs source code…
Sherif
August 14th, 2009 at 7:45 am
11Juergen, Yes, I encourage you to do it and let me know if you have any questions about it.
This is a good opportunity to change some code to make your site look more unique. You are changing the code in your template only, so you should not have any problem when upgrading WordPress in the future.
Good Luck!
Alison
November 24th, 2009 at 2:12 am
12This code is great, but I’m having trouble with styling the text in the template I’m using for the password protected page.
Sherif
December 5th, 2009 at 10:14 am
13Alison, if you send me the template you are trying to use it with, I can set it up for you.
Regards.
RSS feed for comments on this post · TrackBack URI
Leave a reply
Welcome ...
My name is Sherif Elsisi and on this blog I share my knowledge, discovery and experience with hosting issues, Webmaster tools, security and usability.
About Me | Free blog setup | Value added Web Hosting
Categories
Archives
Links
Sponsors
Calendar
Select eBooks
Most Popular Posts
Latest Posts
Your Testimonials
News Headlines
Article Headlines
Web Hosting
Wordpress
Most Commented
Tdot – Blog hosted by TdotHost | BloggingPro theme by: Design Disease | Hosting and Blogging Guide is powered by WordPress