Add Login Logout Links To The Custom Menu Area


This short tutorial will show you how to easily add Login / Logout links for your users in your custom primary navigation menu within your theme.

  1. Create a custom menu from AppearanceMenus and add it to the Primary Menu area.

  1. Open your themes functions.php file and add the PHP code below into that file.
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if ( is_user_logged_in() && $args->theme_location == 'primary' ) {
$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
elseif ( !is_user_logged_in() && $args->theme_location == 'primary' ) {
$items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
return $items;
view raw functions.php hosted with ❤ by GitHub


Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Powered by Zendesk