• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Adding Login/Logout button to custom header menu in Parallax Pro

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Adding Login/Logout button to custom header menu in Parallax Pro

This topic is: not resolved

Tagged: custom, functions, login, logout, menu, theme location

  • This topic has 3 replies, 2 voices, and was last updated 7 years, 6 months ago by ZachScr.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • September 8, 2015 at 7:06 pm #164979
    ZachScr
    Member

    Hi there,

    I just posted this question in a thread but realized that the thread had been resolved so I figured it might get overlooked:

    I’m trying to add a Login|Logout button to my website’s menu (parallax pro). I want the button to say “Logout” when the user is
    logged in, and “login” when they’re logged out. I’ve found a good way to do this by adding custom code to the functions.php file.

    The code that I’m adding looks like this:

    //Add login/logout link to naviagation menu
    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 = '<a href="' . wp_logout_url( $redirect ) . '" title="' .  __( 'Logout' ) .'">' . __( 'Logout' ) . '</a>';
    	else  $link = '<a href="' . wp_login_url( $redirect  ) . '" title="' .  __( 'Login' ) .'">' . __( 'Login' ) . '</a>';
    
    	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 );

    Thing is, it only seems to work when the custom menu I’m using is set to “primary navigation menu”. Of course if I set it as the primary navigation menu, it displays it a second time under the header (and the login/out button only appears on the primary one below the header). So I’d like to add the menu item to the custom menu without making it a “primary navigation menu”.

    I think the issue is in the theme location section above, as it says I should change the theme location to my location name but I’m not sure what to change it to instead of “primary”.

    Anyone have any ideas? I feel like I’ve tried everything.

    http://imakejams.com
    September 8, 2015 at 7:30 pm #164981
    Victor Font
    Moderator

    Take a look at this plugin: https://github.com/GaryJones/genesis-header-nav

    It adds a new menu location for header nav. If you use that plugin, the location would be header.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    September 8, 2015 at 7:51 pm #164991
    ZachScr
    Member

    Victor! It worked! thank you so much.

    Had to do a little CSS editing for it to sit correctly, but it looks good.

    One more question, do you know if it's possible to use a custom login url and a custom redirect link after they are logged out?

    September 9, 2015 at 8:17 am #165027
    ZachScr
    Member

    Nevermind. I figured it out!

    For anyone looking for the same answer, I ended up replacing the wp_login_url and wp_logout_url with my own custom ones and that worked. So it looked like this:

    //Add login/logout link to naviagation menu
    function add_login_out_item_to_menu( $items, $args ){
    
    	//change theme location with your them location name
    	if( is_admin() ||  $args->theme_location != 'header' )
    		return $items; 
    
    	$redirect = ( is_home() ) ? false : get_permalink();
    	if( is_user_logged_in( ) )
    		$link = '<a href="' . wp_logout_url( home_url() ) . '" title="' .  __( 'Logout' ) .'">' . __( 'Logout' ) . '</a>';
    	else  $link = '<a href="' . site_url( '/log-in/' ) . '" title="' .  __( 'Login' ) .'">' . __( 'Login' ) . '</a>';
    
    	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 );
  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble