SHARE
TWEET

Add login / logout to Primary Navigation

jamiemarsland Jun 18th, 2013 3,557 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
  2. function add_loginout_link( $items, $args ) {
  3.     if (is_user_logged_in() && $args->theme_location == 'primary-menu') {
  4.         $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
  5.     }
  6.     elseif (!is_user_logged_in() && $args->theme_location == 'primary-menu') {
  7.         $items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
  8.     }
  9.     return $items;
  10. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top