Skip to content

Instantly share code, notes, and snippets.

@brycejacobson
Created February 11, 2014 17:14
Show Gist options
  • Save brycejacobson/8939385 to your computer and use it in GitHub Desktop.
Save brycejacobson/8939385 to your computer and use it in GitHub Desktop.
Programmatically add menu Item in WordPress
<?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