Skip to content

Instantly share code, notes, and snippets.

@Njengah
Created February 25, 2020 17:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Njengah/fa96025717308df1b979e77e5da3eef2 to your computer and use it in GitHub Desktop.
Save Njengah/fa96025717308df1b979e77e5da3eef2 to your computer and use it in GitHub Desktop.
Create Custom WordPress login form without plugin [ WordPress Login form Shortcode ]
<?php
/**
* Code to Create Custom WordPress login form without plugin
* @author Joe Njenga
* @ gist -
*/
// Step 1: Create shortcode
function njengah_add_login_shortcode() {
add_shortcode( 'jay-login-form', 'njengah_login_form_shortcode' );
}
//Step 2: Shortcode callback
function njengah_login_form_shortcode() {
if (is_user_logged_in())
return '<p>Welcome. You are logged in!</p>'; ?>
<div class ="njengah-login-tutorial" >
<?php return wp_login_form(
array(
'echo' => false ,
'label_username' => __( 'Your Username ' ),
'label_password' => __( 'Your Password' ),
'label_remember' => __( 'Remember Me' )
)
); ?>
</div>
<?php
}
// Step 3 : Init the shortcode function
add_action( 'init', 'njengah_add_login_shortcode' );
//Step 4 : Use the shortcode [njengah-login-form] to embed the login form on a page or post
@chinmayrajyaguru
Copy link

Please correct Step 4.
Use the shortcode [jay-login-form]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment