• Home
  • About Mitch
  • Speaking
  • Articles
  • Contact
  • Home
  • About Mitch
  • Speaking
  • Articles
  • Contact

Digital Strategist

WordPress Developer

Content Creator

Unapologetic Punk

Mitch Canter

  • X
  • Bluesky
  • GitHub
  • Twitch
  • YouTube
  • LinkedIn
Tutorial

Adding A WordPress Login Box To A Template

CMDR Mitchcraft

Reading time: 2 minutes

Sometimes, when you’re taking WordPress beyond a typical blog setup, the need arises to leverage the accounts system in WordPress (to purchase items, to access information, etc).  Earlier on I told you how to check to see if a user is logged in, but when your only login box is in the back-end, that makes it hard.  The first time a client told me I needed to drop in a login box, I panicked.  Forms aren’t the most fun to work with, and getting it to work exactly right with WordPress can be a real pain.

Unless, there’s a function that does it for you.

[code]

<?php wp_login_form(); ?>

[/code]

That’s it.  That single line of code will pull an entire login box to whatever template you have.  The best part?  You can style it however you like.  If you want, you can even create a page template called “Login”, put the form there, style it to match your site, and users may never even know the difference.

There are a few variables you can add in the form of an $args variable.

[code]

<?php $args = array(
‘echo’ => true,
‘redirect’ => site_url( $_SERVER[‘REQUEST_URI’] ),
‘form_id’ => ‘loginform’,
‘label_username’ => __( ‘Username’ ),
‘label_password’ => __( ‘Password’ ),
‘label_remember’ => __( ‘Remember Me’ ),
‘label_log_in’ => __( ‘Log In’ ),
‘id_username’ => ‘user_login’,
‘id_password’ => ‘user_pass’,
‘id_remember’ => ‘rememberme’,
‘id_submit’ => ‘wp-submit’,
‘remember’ => true,
‘value_username’ => NULL,
‘value_remember’ => false ); ?>

[/code]

The important ones would be ‘redirect’ and the various labels.  Redirect allows you to specify where the user lands once they’ve logged in – default is the current page.  The labels change the username/password field labels to whatever you want.

Otherwise, it’s completely customizable.  Use it in sidebars, lightboxes, and even the footer; since you can style it, you can put it anywhere.

One caveat: if the user does anything wrong, it will take them to the typical WordPress login screen, so if you’re nervous about that sort of thing, you  may want to take proper precaution.  Branding the login page, and using a login redirection plugin to direct users once they’ve logged in will help any of the stragglers find their way.

login form, WordPress, wp_login_form
  • Things I Learned from #wcatl (and a Few I Learned on My Own)

    Things I Learned from #wcatl (and a Few I Learned on My Own)

    Reading time: 1 minute

    View more documents from Jane Wells. 2. The PHP and WordPress communities can learn a lot from each other. @technosailor gave a fantastic presentation (re: lecture in a discussion-y way) on how the core communities of both the PHP world and the WordPress world could stand to play nicer to each other.  Personally, I think…

    WordPress
  • Two Recently Updated Plugins YOU Should Be Using

    Two Recently Updated Plugins YOU Should Be Using

    Reading time: 1 minute

    Every now and then, just because I’m the biggest WordPress dork I know, I like to just peruse the plugin database to see what’s been updated recently.  After all, how can you use new plugins if you don’t know they’re there?  I’m glad I looked when I did – I found a few plugins that…

    WordPress