Last active
March 22, 2018 16:11
-
-
Save beatwiz/f8a211395653136e58e8b4f1dac7a7c9 to your computer and use it in GitHub Desktop.
[wordpress] Add login/logout link to wordpress menu based on user login status
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
<?php | |
// ADD LOGIN / LOGOUT FUNCTION TO MENU | |
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2); | |
function add_login_logout_link($items, $args) { | |
ob_start(); | |
wp_loginout('index.php'); | |
$loginoutlink = ob_get_contents(); | |
ob_end_clean(); | |
$items .= '<li>'. $loginoutlink .'</li>'; return $items; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment