Created
February 11, 2014 17:14
-
-
Save brycejacobson/8939385 to your computer and use it in GitHub Desktop.
Programmatically add menu Item in WordPress
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_filter( 'wp_nav_menu_items', 'add_logout_link', 10, 2); | |
/** | |
* Add a login link to the members navigation | |
*/ | |
function add_logout_link( $items, $args ) | |
{ | |
if($args->theme_location == 'site_navigation') | |
{ | |
if(is_user_logged_in()) | |
{ | |
$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>'; | |
} else { | |
$items .= '<li><a href="'. wp_login_url() .'">Log In</a></li>'; | |
} | |
} | |
return $items; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment