Skip to content

Instantly share code, notes, and snippets.

@WebEndevSnippets
Created October 20, 2012 15:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebEndevSnippets/3923584 to your computer and use it in GitHub Desktop.
Save WebEndevSnippets/3923584 to your computer and use it in GitHub Desktop.
WordPress: Add Login In Navigation (w Profile)
// Add Login Link in Navigation
add_filter( 'wp_nav_menu_items', 'we_nav_login_right', 10, 2 );
function we_nav_login_right($menu, $args) {
$args = (array)$args;
$login = wp_loginout( $_SERVER['REQUEST_URI'], false );
$profile = '<a class="profile" href=' . get_edit_profile_url($userid) . '>Profile</a>';
//if not primary, return
//change primary to secondary for secondary menu (though will need some CSS done)
if ( $args['theme_location'] != 'primary' )
return $menu;
if ( !is_user_logged_in() ) {
$menu .= '<li class="right login">' . $login . '</li>';
return $menu;
}
else {
$menu .= '<li class="right login">' . $login . ' | ' . $profile . '</li>';
return $menu;
}
}
/* Login | Profile in Nav
------------------------------------------------------------ */
#nav li.login a {
background: url(images/user.png) no-repeat left center;
padding: 7px 2px 6px 20px;
}
#nav li.login a.profile {
background: none;
padding: 7px 7px 6px 2px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment