Skip to content

Instantly share code, notes, and snippets.

@dexit
Forked from neilgee/login-out.php
Created April 28, 2020 20:59
Show Gist options
  • Save dexit/e6b608b26dbfe3c81f714a058ca4f10b to your computer and use it in GitHub Desktop.
Save dexit/e6b608b26dbfe3c81f714a058ca4f10b to your computer and use it in GitHub Desktop.
Login/Logout Shortcode
<?php //<~ remove if using in functions.php
add_shortcode( 'login_logut', 'login_logut' );
/**
* Add a login/logout shortcode button
* @since 1.0.0
*/
function login_logut() {
ob_start();
if (is_user_logged_in()) :
// Set the logout URL - below it is set to the root URL
?>
<a role="button" href="<?php echo wp_logout_url('/'); ?>">Log Out</a>
<?php
else :
// Set the login URL - below it is set to get_permalink() - you can set that to whatever URL eg '/whatever'
?>
<a role="button" href="<?php echo wp_login_url(get_permalink()); ?>">Log In</span></a>
<?php
endif;
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment