Skip to content

Instantly share code, notes, and snippets.

@texe
Last active July 7, 2022 12:21
Show Gist options
  • Save texe/c82c465056ca6f05bbc4ed30c81e819a to your computer and use it in GitHub Desktop.
Save texe/c82c465056ca6f05bbc4ed30c81e819a to your computer and use it in GitHub Desktop.
WordPress - Login/logout link depends on user is logged
// shortcode for Login/register vs Logout
function md_login_logout() {
if ( is_user_logged_in()) {
$link = '<a href="' . wp_logout_url() . '">Logout</a>';
}
if ( !is_user_logged_in()) {
$link = '<a href="/my-account/edit-account/">Login/Register</a>';
}
return $link;
}
add_shortcode('md_login_logout_link', 'md_login_logout');
//Paste shortcode [md_login_logout_link] in the place you want to get Login/Logout links
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment