Skip to content

Instantly share code, notes, and snippets.

@smartdeal
Last active May 8, 2018 15:53
Show Gist options
  • Save smartdeal/a2e7d92df769f8cfd152bc56ec675643 to your computer and use it in GitHub Desktop.
Save smartdeal/a2e7d92df769f8cfd152bc56ec675643 to your computer and use it in GitHub Desktop.
[Add Custom Items to Specific WordPress Menus] #Wordpress #WP_Menu
<?php
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
}
return $items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment