Are you looking for a way to add a simple login form anywhere on your website? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display WordPress login form anywhere with
All you have to do is add this code to any of your theme’s template file:
<?php wp_login_form(); ?>
If you’re looking for a more advanced login snippet that includes custom fields and options, then you can use this code snippet.
<?php $args = array( 'echo' => true, 'redirect' => 'http://wpsnipp.com', '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 ); wp_login_form($args); ?>
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 25 must have WordPress plugins and how to easily switch from Squarespace to WordPress.