Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Last active March 15, 2022 01:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wpscholar/b15d0d9c60c9d0c7ed513d146e8a46da to your computer and use it in GitHub Desktop.
Save wpscholar/b15d0d9c60c9d0c7ed513d146e8a46da to your computer and use it in GitHub Desktop.
Automatically append login and logout links to a specific menu location.
<?php
add_filter(
'wp_nav_menu_items',
function( $items, $args ) {
if ( 'primary_nav' === $args->theme_location ) {
if ( is_user_logged_in() ) {
$items .= '<li><a title="Log Out" href="' . esc_url( wp_logout_url() ) . '">' . __( 'Log Out', 'cobb-realtors' ) . '</a></li>';
} else {
$items .= '<li><a title="Login" href="' . esc_url( wp_login_url() ) . '">' . __( 'Login', 'cobb-realtors' ) . ' </a ></li >';
}
}
return $items;
},
10,
2
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment