Created
February 14, 2019 16:39
-
-
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
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 | |
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