-
-
Save dexit/e6b608b26dbfe3c81f714a058ca4f10b to your computer and use it in GitHub Desktop.
Login/Logout Shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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