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>
Click here to download login form listed above.
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: 56% [?]
26 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.
Virginia
May 12th, 2010 at 1:42 pm
14Hello. I have a WordPress site where I need separate logins for two separate sections of the site. There is a Parent section and a Teacher section. The parents should not be able to access the teacher’s section (I hope I’m making sense). Is this possible with WordPress. Right now I have to manually change the “role” of a Teacher and they do not have immediate access.
Sherif
May 12th, 2010 at 10:04 pm
15Hi, yes it is possible if you create 2 sets of roles, one for Teachers and one for parents. You will have to do some programming to control viewing the posts by roles, or you might find a useful plugin that can do it. Search membership plugins for wordpress. I think that will do it. Also, if you wait for WordPress 3 to come, it will be easier. WordPress 3 should include functionality of Multi user wordpress, which I think should be implementing your request without even a need for a plugin.
Regards.
Betina
July 27th, 2010 at 5:23 pm
16Great post! Is it possible to create a login for users only. Giving them access only to the front-end and not the back-end? The idea is to password protect the entire content of the site and only give users/subscribers access to front-end posts.
Sherif
July 28th, 2010 at 8:55 pm
17Hi Betina
If you follow the steps here the user should be redirected to the post without having to go to the backend.
I would give the users role the least capabilities and this way, if they stumble on the back-end they would not be able to do anything. You can also try to play with the role manager wordpress plugin or a memebership plugin to control access to your content. If you have more questions, please let me know.
Ferdinand
August 18th, 2010 at 10:27 am
18Hi,
Same with Brian, it does not work for me also. What do you mean by quotes (I noticed when pasting the code, the stylesheet changes the quotes ” and this is failing)
Help please.
Thanks!
Ferdinand
August 18th, 2010 at 10:33 am
19And when i save it, dreamweaver says ” The document’s current encoding can not correctly save all of the characters within the document. You may want to change to UTF-8 or an encoding that supports special characters in this document.” – i have no idea what it means!
Sherif
August 18th, 2010 at 11:01 pm
20Hi Ferdinand,
Sorry about that, I forgot to add the link. Please click here to download the form.
This should also fix the encoding problem.
I also added a link in the post above.
Good luck.
weridrubikscube
July 13th, 2011 at 1:50 pm
21exactly what I was looking for !
though I have a question, how can I prevent the page to be redirected to /wp-login.php if a wrong password is entered ? (I’d rather prefer to have an error message appear in the form itself)
thanks for your help !!
Sherif
July 21st, 2011 at 11:08 pm
22Thank you. I haven’t found anything that will do everything, even the BuddyPress plugin falls short of redirecting all the pages.
Check out this plugin, it redirects error messages and works on WordPress 3+ without issues.
http://blue-anvil.com/archives/a-wordpress-login-widget-sidebar-login-widget-v10/
comptricks
October 4th, 2011 at 5:17 pm
23really great post .. thank you keep it up !
Brian
November 12th, 2011 at 5:12 pm
24I have made a client login page and I would like to have a form input for password and then hit the button.
when you hit the button it would redirect them to their passworded page
each client would have there own page
is this possible? I’ve bee doing a ton of searches but cant find any help. this is for wordpress
Mike G
March 1st, 2012 at 1:30 pm
25Hi, thanks for posting this code its been very helpful for me.
I’m wondering if you can help me tweek it though?I want to be able to change the page to which you goes to after you login?
Sherif
March 1st, 2012 at 11:49 pm
26Sure, please contact me with more detail.
RSS feed for comments on this post · TrackBack URI
Have your say, your comments are very welcome.
I appreciate you taking the time to comment, please consider the following when commenting:
- Use your real name or a pseudonym you frequently use.
- Be relevant and contributive to the post.
- If you want to ad a link, pick a relevant link to the post.
Please note: I reserve the right to edit, censor, and/or delete any comment.
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
Links
Sponsors
Archives
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