Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.