Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Embed a Login form in a page using a shortcode WordPress

  • SOLVED

Hi guys,

Pretty much says it all really.

I'd like to be able to add a login form to a page (not by adding php into the template) using the following shortcode:

[Login]

Can anyone provide me with the function & basic CSS to do this?

NOTE*** This should not re-direct the user to the standard Login page, but place that form in the page.

Thanks

***UPDATE*** sorry guys I forgot to say I'm not interested in plugins. Just a function and styling. Thanks though ;)

Answers (4)

2011-06-10

Marko Nikolic answers:

Hi,

try using this plugin:

http://pippinsplugins.com/wordpress-login-form-short-code/


Is that what you need?



**** EDIT ****

Go to page where you added shortcode, and with Firebug (in Firefox) check id's and classes which affect that part.

I can send you, just need time to install plugin and to collect all info.


Justin Walmsley comments:

Hi Marko,

I came accross that function earlier today before posting here.

The function works fine, but I couldn't see anyway of adding any styles to it.

If you can help with basic styling of the pippinsplugins.com code I'll gladly award you the prize money!

Here is the code as a refresher:

function pippin_login_form_shortcode( $atts, $content = null ) {

extract( shortcode_atts( array(
'redirect' => ''
), $atts ) );

if (!is_user_logged_in()) {
if($redirect) {
$redirect_url = $redirect;
} else {
$redirect_url = get_permalink();
}
$form = wp_login_form(array('echo' => false, 'redirect' => $redirect_url ));
}
return $form;
}
add_shortcode('loginform', 'pippin_login_form_shortcode');


Justin Walmsley comments:

Just rememberd that the function also doens't show if the user is logged in, ideally I just want the login form to always be displayed, or a message saying "You are already logged in"


Marko Nikolic comments:

This is code I pulled out with firebug:
<form method="post" action="http://localhost/development/wp-login.php" id="loginform" name="loginform">

<p class="login-username">
<label for="user_login">Username</label>
<input type="text" tabindex="10" size="20" value="" class="input" id="user_login" name="log">
</p>
<p class="login-password">
<label for="user_pass">Password</label>
<input type="password" tabindex="20" size="20" value="" class="input" id="user_pass" name="pwd">
</p>

<p class="login-remember"><label><input type="checkbox" tabindex="90" value="forever" id="rememberme" name="rememberme"> Remember Me</label></p>
<p class="login-submit">
<input type="submit" tabindex="100" value="Log In" class="button-primary" id="wp-submit" name="wp-submit">
<input type="hidden" value="http://localhost" name="redirect_to">
</p>

</form>


So use it's id's and classes to style it with css.


******ONE IMPORTANT NOTICE******

I checked it in Chrome, didn't work, it shows only blank page. In Firefox works well.


Marko Nikolic comments:

What a fool I am :) it's because I was logged in on Chrome. Sorry, I'll check now.


Marko Nikolic comments:

This is it.
function pippin_login_form_shortcode( $atts, $content = null ) {



extract( shortcode_atts( array(

'redirect' => ''

), $atts ) );



if (is_user_logged_in()) {

echo '<p style="clear:both;">You are already logged in</p>';

} else {
if($redirect) {

$redirect_url = $redirect;

} else {

$redirect_url = get_permalink();

}

$form = wp_login_form(array('echo' => false, 'redirect' => $redirect_url ));

}
return $form;


}

add_shortcode('loginform', 'pippin_login_form_shortcode');

2011-06-10

Cristian Antohe answers:

You can use Profile Builder plugin:
http://www.cozmoslabs.com/2011/04/12/wordpress-profile-builder-a-front-end-user-registration-login-and-edit-profile-plugin/

There is also a beta version with a bit more extra functionality if you're interested:
http://www.cozmoslabs.com/profile-builder-beta/

2011-06-10

Nilesh shiragave answers:

I hope this code snippet will be fine for you


function pippin_login_form_shortcode( $atts, $content = null ) {

extract( shortcode_atts( array(
'redirect' => ''
), $atts ) );

if (!is_user_logged_in()) {
if($redirect) {
$redirect_url = $redirect;
} else {
$redirect_url = get_permalink();
}
$form = wp_login_form(array('echo' => false, 'redirect' => $redirect_url ));
}
return $form;
}
add_shortcode('loginform', 'pippin_login_form_shortcode');


Check more details at
http://pippinsplugins.com/wordpress-login-form-short-code/

2011-06-11

Lucas Wynne answers:

There are two plugins that do this wonderfully, I use both of them on separate sites.

For a easy one try:
http://wordpress.org/extend/plugins/theme-my-login/

For something a bit more in-depth try this out:
http://tareq.wedevs.com/2011/01/new-plugin-wordpress-user-frontend/

I hope these will help you out. Let me know if you have any questions!