Skip to content

Instantly share code, notes, and snippets.

@rafpro
Forked from brycejacobson/functions.php
Created December 12, 2018 09:49
Show Gist options
  • Save rafpro/e816e06550fae99790f6673c2d799650 to your computer and use it in GitHub Desktop.
Save rafpro/e816e06550fae99790f6673c2d799650 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