How To Add A WordPress Login Form Using Widgets (Shortcode)

WordPress login form widget

Login To WordPress With Your Email AddressA WordPress user login form is a great way to provide fast access to your WordPress blog or website for administrators to subscribers. Unfortunately, WordPress does not provide a standard WordPress login widget, which we think should be included in all WordPress systems.

  • In this article/tutorial, we are not going to make a widget, but a shortcode for a login form which can be inserted into widgets through text.
A shortcode in widgets?

WordPress does not automatically allow shortcodes in widgets without the use of the do_shortcode function. So, we have taken this do_shortcode function and  a wp_login_form function from DevPress, which together allows you to place a WordPress login form shortcode in a widget slot… or allows you to use any other shortcode in widgets. (Also see: Using shortcodes in template files)

  • Learn more about styling the WordPress login form.
  • Down 1. Copy and paste the code below into your functions.php file
    [Normal_Box]

    add_filter('widget_text', 'do_shortcode');
    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' );

    [/Normal_Box]
    WordPress Login Form Widget ShortcodeUse Shortcode 2. Use shortcode:
    [devpress-login-form]
    inside text in any widget slot.


    Sean Doyle

    http://Botcrawl.com

    Sean Doyle is an engineer from Los Angeles, California. Sean's primary focuses include Internet Security, Web Spam, and Online Marketing.