I added a login/register and a logout menu item to my navigation. Therefore I used following code in my theme’s functions.php script:
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'footer') {
$items .= '<li><a href="'. wp_logout_url() .'">Logout</a></li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'footer') {
$items .= '<li><a href="'. site_url('my-account') .'">Login/Register</a></li>';
}
return $items;
}
So if the user is logged in the logout menu item will show up, otherwise the login/register menu item. But I have a bilingual website using wpml and would like to know how to make the “Login/Register”-string translatable.
I already tried this:
$items .= '<li><a href="'. site_url('my-account') .'">'.__('Login/Register').'</a></li>';
and also this:
$items .= '<li><a href="'. site_url('my-account') .'">'.__('Login/Register', 'theme_name').'</a></li>';
but it didn’t work. According to this it should be enough to display the string in the dashboard menu -> wpml -> string translation
So what did I wrong?
Solved:
According to one answer of this post: Why strings don’t appear in “String translation” of WPML? I just had to scan the theme again for strings then it showed up!
This line of code I used: