WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding login/logout to thte menu (7 posts)

  1. Michael Johansen
    Member
    Posted 3 years ago #

    Hi,

    In an attempt to add login/logout to my menu, I've added this code to my function.php

    /* LogIn - LogOut */
    
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
    function add_login_logout_link($items, $args) {
    
    		ob_start();
    		wp_loginout('index.php');
    		$loginoutlink = ob_get_contents();
    		ob_end_clean();
    
    		$items .= '<li>'. $loginoutlink .'</li>';
    
    	return $items;
    }
    
    /* LogIn - LogOut END */

    My problem is, that the login/logout now appears in both the page menu as well as the category menu.

    How do I make it appear only in the page menu?

    Help greatly appreciated thank you,

    Michael :)

    (http://www.buildinganonline.com/)

  2. Tara
    Member
    Posted 3 years ago #

  3. Michael Johansen
    Member
    Posted 3 years ago #

    Thank you t-p,

    Well that was easy, and much more clever than the function.

    But I use a very advanced theme and no matter how much I try to integrate the, yet very simple, MU Theme login, it doesn't work for my theme.

    I've tried it out on other themes with success, so it has to do with the theme for sure.

    What I've done instead, is to add a costume link to the menu, but only to login.

    Could anyone please tell me if it's possible to program a costume link to work as BOTH login and logout?

    Once again t-p, thank you for your help :)

    Regards,
    Michael

  4. bluejpro
    Member
    Posted 2 years ago #

    I did the same thing - added a login/out link with the function you show at the top.

    And I had the same problem: all menus got the link, not just the one I wanted.

    Here is the post with a function that lets you select the menu for the login/out link:

    http://wpsmith.net/2011/tutorials/how-to-add-a-log-inlog-out-link-to-a-specific-custom-menu/

  5. bluejpro
    Member
    Posted 2 years ago #

  6. Hax
    Member
    Posted 2 years ago #

    Here is a better and cleaner way to do it
    http://xparkmedia.com/2012/04/add-login-logout-link-menu/

  7. Svitlana21
    Member
    Posted 2 years ago #

    No extra coding is needed. Here is easy to use plugin - BAW Login/Logout menu:
    http://wordpress.org/extend/plugins/baw-login-logout-menu/

Topic Closed

This topic has been closed to new replies.

About this Topic