Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator bcworkz

    (@bcworkz)

    Have you tried replacing the is_user_logged_in logic of the above code with something like this?

    if( is_user_logged_in( ) )
        $link = '<a href="account-page.htm" class="login">Account</a>';
    else
        $link = '<a href="subsciption-page.htm" class="login">Subscribe Now</a>';

    Adjust the hrefs to the actual page URLs of course.

    Thread Starter Recker

    (@recker)

    I tried that, It just showed a black screen! Didn’t load any of the site.
    Though it didn’t show any error code either, So It must be in the right direction!

    Moderator bcworkz

    (@bcworkz)

    Have you checked for javascript errors? The modal script may be crashing because it’s elements have become malformed. It needs to be kept happy or removed, depending on which way you’re going with this.

    Thread Starter Recker

    (@recker)

    Where would a javascript error log be found?
    And I need the modal login/logout connected to the main menu. And it would be useful to have this to!

    Since I’m basically repeating code with a different layout, I don’t need this part again do i?

    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;

    Thanks for the help!
    – Jamie

    Moderator bcworkz

    (@bcworkz)

    Where Javascript errors show up is browser dependent. On FF it’s “Error Console” under “Web Developer”.

    Yes you only need that snippet once, it suppresses anything that follows under certain conditions.

    If the modal script works the way I think it does, the added menu items should work if you assign the same class. But it’s conceivable the script may need some tweaking, especially considering that now nothing appears to be working. Hopefully there are clues in the error console, otherwise I’m out of ideas.

    Thread Starter Recker

    (@recker)

    I’ve managed to get it partly working!: protipsters.co.uk

    This is the code I’m using:

    /*Add Modal Menu Login/Logout*/
    function add_login_out_item_to_menu( $items, $args ){
    
    	//change theme location with your theme location name
    	if( is_admin() ||  $args->theme_location != 'primary' )
    		return $items; 
    
    		if( is_user_logged_in( ) )
        $link = '<a href="protipsters.co.uk/account" class="login">Account</a>';
    else
        $link = '<a href="protipsters.co.uk/subscription" class="login">Subscribe Now</a>';
    
    	$redirect = ( is_home() ) ? false : get_permalink();
    	if( is_user_logged_in( ) )
    		$link = do_shortcode('[modal_login login_text="Members Login" logout_text="Logout" logout_url="/"]');
    	else  $link = do_shortcode('[modal_login login_text="Members Login" logout_text="Logout" 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 );

    The issue I’m having now is that the Subscribe Now/Account button is stuck on Account all the time. It doesn’t change name, but it does appear to do what it’s meant to do!

    Thread Starter Recker

    (@recker)

    No, i’m wrong again! The cache hadn’t cleared and it was still showing an old link to account via role redirect.

    Still haven’t managed to get it into a menu!

    Moderator bcworkz

    (@bcworkz)

    Well, I see one problem. The subsequent $link = do_shortcode(\\... lines are overwriting your $link assignments so it’s like they were never there. You need to concatenate additional content to $items after each step. Add this above the $redirect = ( is_home()\\... line:
    $items .= $link;

    This may not be the only problem, but it’s certainly a big problem.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Showing/Changing Menu Items with Login/Logout’ is closed to new replies.