• Use this code (functions.php) for login logout in menu bar

    function add_login_out_item_to_menu( $items, $args ){
    
    	//change theme location with your them location name
    	if( is_admin() ||  $args->theme_location != 'primary' )
    		return $items; 
    
    	$redirect = ( is_home() ) ? false : get_permalink();
    	if( is_user_logged_in( ) )
    		$link = do_shortcode('[wp-modal-login login_text="inloggen" logout_text="Uitloggen" logout_url="/"]');
    	else  $link = do_shortcode('[wp-modal-login login_text="inloggen" logout_text="Uitloggen" logout_url="/"]');
    
    	return $items.= '<li id="log-in-out-link" class="menu-item menu-type-link">'. $link . '</li>';
    }add_filter( 'wp_nav_menu_items', 'add_login_out_item_to_menu', 50, 2 );

    http://wordpress.org/plugins/wp-modal-login/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hey,
    Thank you that worked perfectly!

    I was wondering if by any chance you knew how to tweak the code to do this:

    If not logged in show ‘Link A’
    When logged in show ‘link B’ in place,

    but rather then calling a shortcode it would be a page link.

    I tried it myself but I caused my entire site to error and break.
    So I thought I’d ask you!

    regards,
    Jamie

    Thread Starter fort123

    (@fort123)

    replace
    do_shortcode(‘[wp-modal-login login_text=”inloggen” logout_text=”Uitloggen” logout_url=”/”]

    with your link

    So that part of the code would simply be:

    $link = http://www.mysite.com logout_url="/"]');
    else  $link = http://www.mysite.com logout_text="Uitloggen" logout_url="/"]');

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Is that correct?

    What do I need to do if I want to keep the login_text/logout_text?
    I need to changing the word just like the function you provided, but just linking to other pages rather than the shortcode.

    Sorry, I’m new to this 🙂

    Hi,

    Thanks

    I’ve added the code to my functions.php, but do not see an option in my menu.

    My code:

    if( is_admin() || $args->theme_location != 'skeleton-childtheme' )

    cant find an additional option in my menu?

    Am new to wordpress but i like your plugin very much.
    I want to include it in my top menu
    please help me out

    Should i past this code in my function.php ?
    or i need to do some thing else ?

    function add_login_out_item_to_menu( $items, $args ){

    //change theme location with your them location name
    if( is_admin() || $args->theme_location != ‘primary’ )
    return $items;

    $redirect = ( is_home() ) ? false : get_permalink();
    if( is_user_logged_in( ) )
    $link = do_shortcode(‘[wp-modal-login login_text=”inloggen” logout_text=”Uitloggen” logout_url=”/”]’);
    else $link = do_shortcode(‘[wp-modal-login login_text=”inloggen” logout_text=”Uitloggen” logout_url=”/”]’);

    return $items.= ‘<li id=”log-in-out-link” class=”menu-item menu-type-link”>’. $link . ”;
    }add_filter( ‘wp_nav_menu_items’, ‘add_login_out_item_to_menu’, 50, 2 );

    @emmanuelbaiden: As per the Forum Welcome, please post your own topic.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘i made something to use in the menu bar’ is closed to new replies.