Skip to content

Instantly share code, notes, and snippets.

@greenhornet79
Created December 4, 2017 16:54
Show Gist options
  • Save greenhornet79/ca585eef737eb5e391321486c37a05ef to your computer and use it in GitHub Desktop.
Save greenhornet79/ca585eef737eb5e391321486c37a05ef to your computer and use it in GitHub Desktop.
login for shortcode for WordPress
<?php
function 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', 'login_form_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment