Skip to content

Instantly share code, notes, and snippets.

@neilgee neilgee/login-out.php
Last active Mar 15, 2019

What would you like to do?
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() {
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>
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>
return ob_get_clean();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.