Skip to content

Instantly share code, notes, and snippets.

@webmasterninjay
Last active August 29, 2015 14:15
Show Gist options
  • Save webmasterninjay/f9050e4e913f34c36c77 to your computer and use it in GitHub Desktop.
Save webmasterninjay/f9050e4e913f34c36c77 to your computer and use it in GitHub Desktop.
WP function to create a shortcode to embed login form on page or post
<?php
// Use the shortcode [jay-login-form] to embed the login form
// Create shortcode
function jay_add_shortcodes() {
add_shortcode( 'jay-login-form', 'jay_login_form_shortcode' );
}
// Shortcode callback
function jay_login_form_shortcode() {
if ( is_user_logged_in() )
return '<p>You are already logged in!</p>';
return wp_login_form( array( 'echo' => false ) );
}
// Init the shortcode function
add_action( 'init', 'jay_add_shortcodes' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment