Forum Replies Created
-
AuthorPosts
-
September 9, 2015 at 8:17 am in reply to: Adding Login/Logout button to custom header menu in Parallax Pro #165027ZachScrMember
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 );
September 8, 2015 at 7:51 pm in reply to: Adding Login/Logout button to custom header menu in Parallax Pro #164991ZachScrMemberVictor! 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?
ZachScrMemberHi there,
Hopefully this is the right place to ask this:
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, I end up with two menu locations as discussed earlier in this thread (and the login/out button is only appears on the primary one). 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 line above but I'm not sure what to target instead of "primary".
Anyone have any ideas? I feel like I've tried everything.
ZachScrMemberWorked perfectly!
Thank you so much, Tonya!
Zach
-
AuthorPosts