Created
April 28, 2015 07:04
-
-
Save cobbman/58a5aa13be978eb7d60a to your computer and use it in GitHub Desktop.
WP Append login/logout links
This file contains hidden or 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
// Add login/logout links to the footer navigation | |
// This will filter through the menu items and look for the footer-menu. | |
// Then append login/logout links to the end | |
function add_loginout_menu_to_footer( $items, $args ) { | |
// only add login/out items to the footer menu | |
if ( is_admin() || $args->theme_location != 'footer-menu' ) // change 'footer-menu' to the name of the menu you want to add the login links to. i.e. change to 'primary' to add links to the primary menu | |
return $items; | |
$link = wp_loginout( $redirect = home_url(), $echo = false ); // use wp_loginout() to return the correct login OR logout link strings | |
// append our new list item to the current menu list items and return it | |
return $items.= '<li class="menu-item menu-type-link" id="log-in-out-link">'. $link . '</li>'; | |
} add_filter( 'wp_nav_menu_items', 'add_loginout_menu_to_footer', 50, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment