Last active
July 7, 2022 12:21
-
-
Save texe/c82c465056ca6f05bbc4ed30c81e819a to your computer and use it in GitHub Desktop.
WordPress - Login/logout link depends on user is logged
This file contains 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
// 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