0

I would like to add a "LogOut" button at the end of my sidemenu - but of course only, if someone is logged in. I also want to have it in two languages using qtranslate.

At the moment I have created a new Menu Item "Log Out" with a link to /wp-login.php?action=logout which works, but always shows up of course.

Is there a way to put something like this in the function? Any help - or just a hint would be very nice! :)

1

To add a menu item to the end of a nav menu you can use the wp_nav_menu_items hook. Combine that with is_user_logged_in() and you ought to have it.

function add_last_nav_item($items) {
  if (!is_user_logged_in()) {
    return $items .= 'your login link';
  }
}
add_filter('wp_nav_menu_items','add_last_nav_item');

As far as translation, I assume that qTranslate uses the standard translation functions, but I'm not sure as I don't use it and as it is a third party plugin that part of the puzzle is off-topic anyway.

  • Thanks! This works great. But how could I tell, that it is only shown in a menu widget called e.g.: shop menu? thanks! – ad2003 May 13 '14 at 17:24
  • I can't quite tell what you are asking but it is going to depend on the widget most likely. Do you have that code? – s_ha_dum May 13 '14 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.