Created
April 10, 2018 19:18
-
-
Save grtaylor2/f2de1e0bb1f2837cc41f337ba1830690 to your computer and use it in GitHub Desktop.
How to Add a Login/Logout Link to Your WordPress Genesis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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() .'">Log Out</a></li>'; | |
} else { | |
$items .= '<li class="menu-item"><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