Adding Register, Login, Logout Links to WordPress Menu

Do you want to add register, login, and logout links or URLs to your WordPress menu?

We are often asked by our customers and blog readers how they can add a login/logout and register or sign-up links to their WordPress navigation menu.

By login/logout, I mean a login link is displayed when the user isn’t logged in; otherwise, a logout link is displayed.

Using ProfilePress Plugin

Firstly, ensure you have the ProfilePress plugin installed and activated.

Navigate to Appearance >> Menu.

You will see a ProfilePress Links metabox on the left-hand side. Expand and add the login, signup, and logout links you want to include to your WordPress website menu.

You can also add the login, logout, lost password, edit profile, and my profile links via the Customizer.

Navigation Menu Link ProfilePress Extension for WordPress

Note: the login and sign-up page links are hidden when a user is logged in. Also, the logout, my profile, and edit profile links are only shown to logged-in users, while in login/logout, the logout link is shown to logged-in users and login to users who aren’t logged in.

Using a Code Snippet

The code snippet below, when added to your theme’s functions.php file or a site-specific plugin, will add signup and login/logout links to your WordPress menu.


function add_login_logout_register_menu( $items, $args ) {
	if ( $args->theme_location != 'primary' ) {
		return $items;
	}

	if ( is_user_logged_in() ) {
		$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
	} else {
		$items .= '<li><a href="'. wp_login_url() .'">Log In</a></li>';
		$items .= '<li><a href="'. wp_registration_url() .'">Sign Up</a></li>';
	}

	return $items;
}

add_filter( 'wp_nav_menu_items', 'add_login_logout_register_menu', 199, 2 );

Note

Using a ProfilePress front-end login, registration, and password reset page as your default, the menu URLs will automatically point to them.

Integrating registration, login, and logout links into your WordPress menu provides a seamless user experience, allowing visitors to navigate seamlessly within your website. I hope this article has been helpful to you.