How to Add Login Logout Link to WordPress Menu

However, the default WordPress menu system does not provide an option for showing certain links when someone is logged in or logged out. Almost nothing is more frustrating for a user than searching around for a login link in order to get to important content.  So to add a login and logout link to your menus you will have to either use custom code or use a plugin that provides this functionality.

How to Add Login Logout Link to WordPress Menu

You will need to add a bit of code to your functions file for this. But after copying and pasting this code, you’re finished.

Go to Appearance > Editor > Theme Functions (functions.php). Place the following code in the bottom your functions file and hit “Update File.”

Add menu login logout

add_filter(‘wp_nav_menu_items’, ‘add_login_logout_link’, 10, 2);
function add_login_logout_link($items, $args) {
$loginoutlink = wp_loginout(site_url(), false);
$items .= ‘<li>’. $loginoutlink .'</li>’;
return $items; }

The Result



You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *