Monday, October 31, 2011

Login form shortcode for WordPress

Here we learn how to displaying login forms on wordpress using a shortcode Paste the following code into functions.php file:

function sandip_login_form_shortcode() {
    if ( is_user_logged_in() )
        return '';

    return wp_login_form( array( 'echo' => false ) );
}

function sandip_add_shortcodes() {
    add_shortcode( 'sandip-login-form', 'sandip_login_form_shortcode' );
}

add_action( 'init', 'sandip_add_shortcodes' );

Once done, we can now use the shortcode as shown in the following example. just paste it on the post editor, where you want the login form to be displayed. [sandip-login-form]

No comments:

Post a Comment

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off