Paste the code below into your functions.php file:
function devpress_login_form_shortcode() {
if ( is_user_logged_in() )
return '';
return wp_login_form( array( 'echo' => false ) );
}
function devpress_add_shortcodes() {
add_shortcode( 'devpress-login-form', 'devpress_login_form_shortcode' );
}
add_action( 'init', 'devpress_add_shortcodes' );
Once done, you can now use the shortcode as shown in the following example. Simply paste it on the post editor, where you want the login form to be displayed.
[devpress-login-form]
Thanks to DevPress for the cool tip!
6 Responses
Hey, why use a shortcode when we can use a widget for login-form that is available by default each we’ve done installing WP?
Tried it but does not work.
function devpress_login_form_shortcode() {
if ( is_user_logged_in() )
return ”;
return wp_login_form( array( ‘echo’ => false ) );
}
It worked when i change array( ‘echo’ => false ) to array( ‘echo’ => true ).
I tried it, also changed false to true, didnt work.
Tested it out as well, with both true and false echos… no luck.
the function is set to return ” when the user is logged in. As you’re likely logged in after inserting the function it’s returning nothing.
Try logging out or using a chrome incognito window…
Trackbacks: