Skip to content

Instantly share code, notes, and snippets.

@beatwiz
Last active March 22, 2018 16:11
Show Gist options
  • Save beatwiz/f8a211395653136e58e8b4f1dac7a7c9 to your computer and use it in GitHub Desktop.
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
<?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