jamiemarsland

Add login / logout to Top Menu

Jun 18th, 2013
2,985
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 == 'top-menu') {
  4. $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
  5. }
  6. elseif (!is_user_logged_in() && $args->theme_location == 'top-menu') {
  7. $items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
  8. }
  9. return $items;
  10. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×