Tagged: dropdown, Language, languages, login, logout, second menu, secondary menu, submenu
-
AuthorPosts
-
April 13, 2014 at 1:21 pm #250745
Hello everyone,
I was trying to create a login and logout for the topnav menu (secondary menu). I have currently written the following:
add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2 ); function my_custom_menu_item ( $items, $args ) { if(is_user_logged_in()){ if (is_object($args) && $args->theme_location == 'avia2'){ $items .= '<li class="menu-item custom-menu-item"><a href="<?php echo wp_logout_url( home_url() ); ?>" rel="nofollow" title="Logout">Logout</a></li>'; } return $items; }else{ if (is_object($args) && $args->theme_location == 'avia2'){ $items .= '<li class="menu-item custom-menu-item"><a href="" rel="nofollow">Login</a><ul class="sub-menu"><li class="menu-item menu-item-type-post_type menu-item-object-page">'.do_shortcode("[av_sidebar widget_area='My ICS Login Menu']").'</li></ul></li>'; } } return $items; }
Login shows when not logged in correct and it makes the dropdown menu = Check.
But … Logout when clicked it doesn’t redirect to home page it just go to the 404 page instead. I can’t see what my mistake should be. I even tried with direct url after.Logout:
- 1. Click on “Logout”.
- 2. Once clicked it should logout the member.
- 3. Once logged out it should also redirect to the homepage, or http://www.domain.com/home/
- 4. If possible it should redirect to that current language also (got English and German languages running with WPML plugin
I’m not too greedy I hope.
Looking forward to your reply.
April 14, 2014 at 6:21 pm #251241Can anyone help me?
April 15, 2014 at 8:59 am #251492Hi!
Try to replace this line:
$items .= '<li class="menu-item custom-menu-item"><a href="<?php echo wp_logout_url( home_url() ); ?>" rel="nofollow" title="Logout">Logout</a></li>';
with:
$items .= '<li class="menu-item custom-menu-item"><a href="'.wp_logout_url(icl_get_home_url()).'" rel="nofollow" title="Logout">Logout</a></li>';
For more information refer to: https://wpml.org/de/documentation-3/support-2/mehrsprachige-wordpress-themen-erstellen/link-zur-startseite/
Cheers!
PeterApril 15, 2014 at 9:35 am #251497Hey Dude,
I tried out what you said and read the link also. None of those options worked out. It still doesn’t logout the user nor redirect.
Further more I forgot to mention that I’m also using the plugin “Login Sidebar” to even make login possible in the secondary menu.
April 15, 2014 at 9:45 am #251499This reply has been marked as private.April 17, 2014 at 7:18 am #252476Hey!
I fixed it. The code line must look like:
$items .= '<li class="menu-item custom-menu-item"><a href="'.wp_logout_url(icl_get_home_url()).'" rel="nofollow" title="Logout">Logout</a></li>';
Regards,
PeterApril 17, 2014 at 9:55 am #252546Ahh…. Yeah okay! Hehe.
Thanks a lot for the help, truly appreciated and amazed at how good the support is for this theme. Without you guys I would say the theme would loose 30% of it’s value. Thanks again!
-
AuthorPosts
- The topic ‘Submenu adding dropdown/hover login/logout widget/buttons’ is closed to new replies.