Skip to content

Instantly share code, notes, and snippets.

@neverything
Created February 14, 2019 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neverything/dd5358ac39d9b9a5699854e798851416 to your computer and use it in GitHub Desktop.
Save neverything/dd5358ac39d9b9a5699854e798851416 to your computer and use it in GitHub Desktop.
Add a custom logout link to the main menu for logged in users
<?php
function wti_loginout_menu_link( $items, $args ) {
if ($args->theme_location == 'primary') { // Adjust this to the menu location.
if (is_user_logged_in()) {
$items .= '<li class="right"><a href="'. wp_logout_url() .'">'. __("Log Out", "textdomain") .'</a></li>';
}
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'wti_loginout_menu_link', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment