Site icon Hip-Hop Website Design and Development

Redirect per shortcode if person is logged in

I wish to put the wordpress login display on my homepage. If a person will not be logged in I need them to should enter their username and password into the field (or join).. and if they’re logged in, I need them to be redirected to the overview web page.

All the pieces works superb if the person will not be logged in, but when they’re logged within the redirect is not working..

Can somebody please inform me what’s flawed with my php code under.

/* add login shortcode */

add_action( 'init', 'my_add_shortcodes' );

operate my_add_shortcodes() {

    add_shortcode( 'my-login-form', 'my_login_form_shortcode' );
}

operate my_login_form_shortcode( $attr ) {

    if ( is_user_logged_in()) {
    wp_redirect('http://michellemarcus.co.za/thinkingmachines/overview/') ;
}

    if ( ! is_user_logged_in() ) 

    /* Arrange some defaults. */
    $defaults = array(
        'label_username' => 'Username',
        'label_password' => 'Password'
    );

    /* Merge the person enter arguments with the defaults. */
    $attr = shortcode_atts( $defaults, $attr );

    /* Set 'echo' to 'false' as a result of we would like it to all the time return as an alternative of print for shortcodes. */
    $attr['echo'] = false;

    return wp_login_form( $attr );
}