PureNews

PureNews is an amazingly sleek and powerful news theme with unlimited color variations.

View full feature list Check out the live demo Buy this theme today

Adding a login box to your site

Posted by on 15th Feb 2009 WordPress Coding & Design 7 comments

If you’re running a multi-author site, or perhaps you allow people to register on your site, then adding the login box into your site would be a nice addition rather than just redirecting people to the standard login page.

You could just copy the form off the wp-login.php page, however it’s not very well marked up, plus you will probably want to fit it into a smaller area on the front end of your site, maybe in your sidebar or at the top right of your web site.

The Login Form

The first job is to put the login form where you want it to go. The code for this is below:

[sourcecode language="html"]

Username

Logged In Users

Of course we don’t need the form displaying if the person is logged in, so we need to add a bit of additional PHP to check if the user is logged in. If they aren’t then we display the form, if they are then we can either display nothing, or display a link to the admin and perhaps a logout link.

To check if the user is logged in we use the is_user_logged_in() conditional, eg.

[sourcecode language="php"]< ?php if (!is_user_logged_in()) : ?>

Username

/wp-admin/”>WP Admin
  • A PHP Developer using WordPress to power both blogging and commercial CMS sites. I've written and released a couple of plugins for WordPress and am currently writing plugins for use on commercial websites.

    7 comments - Leave a reply
    • Posted by Freebies Mentor on 15th Feb 2009

      I have been wanting to add a login box for some time. This should definitely do the trick.

    • Posted by Karol Stofira on 16th Feb 2009

      thank you very much… I need it… and maybe here is some tip for next post,… what I have to do, if I need to my site add code (forms) to write a new post directly from site, not only from admin site… on one of my multi-author sites I want to do this, cause I want facilitate writing for these people..

      one more thanx

    • Posted by Sarah on 16th Feb 2009

      Hi Karol, you would need to use a plugin to allow inline posting/editing. This plugin will do what you need – http://wordpress.org/extend/plugins/admin-managem…

    • Posted by JonryfoednerN on 19th Feb 2009

      Let me start off by saying that I'm a cat lover. I love cats.Indoor cats. Cats who are well cared for and loved.

      Our next door neighbors, who are good people and we have no complaint about, are animal lovers too. They also have three cats. Outdoor

      cats. Oh, and three dogs. Outdoor dogs. (Their back yard is maybe about 4/10's of an acre?) Well, you can imagine that the outdoor cats

      don't feel like spending time with the outdoor dogs… why should they when they can so easily hop the fence and spend time in OUR yard?

      Ordinarily, it wouldn't bother me at all to have a cat roaming through our yard. I LIKE cats. But these guys are wearing out their

      welcome.

      Our poor cats stand at the windows unable to chase those cats off of their territory. We used to let our cats out every now and t

      hen to chew the monkey grass or sniff around (they're declawed… we have to stay with them to make sure they don't escape). We

      can't anymore… the neighbor's cats scent sends one of our males into a frenzy whereby he attacks our other cats.

      We can't leave our garage door up anymore (they pee in our garage). I can't enjoy the birdfeeder anymore (they stalk the birds).

      And just now, I went outside and discovered our yard smells like one of those crazy cat lady houses.

    • Posted by Charlotte on 27th Oct 2010

      Thanks Sarah that really helped me

    • Posted by Charelle on 11th Nov 2010

      i been looking everywhere for this answer im going to try it and see if it works thank you so much