WordPress.org

Ready to get started?Download WordPress

Forums

Log In and Log/Out link in Top Nav menu (2 posts)

  1. autovall
    Member
    Posted 2 years ago #

    Hello,

    How to add Log In/Log Out link in Top Nov menu. The that I have in the right navigation bar in the following link.
    autovalley.co.uk

    In all my links I passed urls of different pages but here I can't pass login page url because I want this text to change to "Log Out" when a user logins.

    Regards,
    Roohullah

  2. Marventus
    Member
    Posted 2 years ago #

    Mods: Could you please change the thread title to Log In and Log/Out link in Top Nav menu so that it gets picked up on search results properly?

    autovall: To add a Login/Out link as a nav menu item, add the following code to your functions.php file:

    function autov_add_loginout_navitem($items) {
    	$login_item = '<li class="login">'.wp_loginout($_SERVER['REQUEST_URI'], false).'</li>';
        $items .= $login_item;
    	return $items;
    }
    add_filter('wp_nav_menu_items', 'autov_add_loginout_navitem');

    That will add a login link to all your menus. If you wish to add the link to only one menu, change the last line to this:

    add_filter('wp_nav_menu_[slug]_items', 'autov_add_loginout_navitem');

    Make sure you replace [slug] with the targeted menu's slug.
    That should do it.
    Cheers!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.