Skip to content

Instantly share code, notes, and snippets.

@nickcernis
Last active May 26, 2018 19:18
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickcernis/02086c75ee9aa19447e0 to your computer and use it in GitHub Desktop.
Save nickcernis/02086c75ee9aa19447e0 to your computer and use it in GitHub Desktop.
Add a login/logout link to the menu bar of any Genesis child theme
<?php // add everything except for this opening line to your functions file
add_filter( 'wp_nav_menu_items', 'sp_add_loginout_link', 10, 2 );
function sp_add_loginout_link( $items, $args ) {
// Change 'primary' to 'secondary' to put the login link in your secondary nav bar.
if ( $args->theme_location != 'primary' ) {
return $items;
}
if ( is_user_logged_in() ) {
$items .= '<li class="menu-item"><a href="' . wp_logout_url( home_url() ) . '">Log Out</a></li>';
} else {
$items .= '<li class="menu-item"><a href="' . site_url( 'wp-login.php' ) . '">Log In</a></li>';
}
return $items;
}
@nickcernis
Copy link
Author

Nice addition, @MissAmeliaSmith! Thanks for sharing it here.

@braddalton
Copy link

Here's another way to do it wp_loginout https://codex.wordpress.org/Function_Reference/wp_loginout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment