Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
Client is attempting to redirect users to the appropriate language-specific login page when clicking "Login" in the Header Navigation Menu of the BuddyBoss theme. The default login URL always points to wp-login.php and does not account for different languages.

Solution:
We recommend saving the current language to a variable using the wpml_current_language hook, which returns the language code of the active language. Then, set conditions for each language to change the returned URL accordingly.

// Get the current language code
$current_language = apply_filters('wpml_current_language', null);

// Check if the current language is English
if ($current_language == 'en') {
  // Redirect to the English login page
} else {
  // Redirect to the login page of other languages
}

If this solution does not seem relevant to your issue, please feel free to open a new support ticket in the WPML support forum.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 1 reply, has 2 voices.

Last updated by Andreas W. 1 year ago.

Assisted by: Andreas W..

Author Posts
January 24, 2024 at 4:17 pm #15222914

calebW-2

TELL US WHAT YOU ARE TRYING TO DO?
Attempting to have the BuddyBoss Theme "Login" function redirect Users to the appropriate language (English/Spanish) login Page when clicking "Login" in the Header Navigation Menu of the BuddyBoss theme. Here is a video describing exactly what we are struggling with: hidden link

IS THERE ANY DOCUMENTATION THAT YOU ARE FOLLOWING?
Yes: hidden link

The BuddyBoss theme has a "Login" and "SignUp" button that come default with the theme (very convenient!) but the LOGIN URL always points to wp-login.php and cannot be customized (the sign up button actually can be customized but not the login URL). If we want to use another page as our default login page instead of wp-login.php, by default the platform does not have this option. However, BuddyBoss does allow us to use the following function code:

function my_login_page( $login_url) {
return ( '/login/' );
}
add_filter( 'login_url', 'my_login_page', 10 );

That code works great except that it redirects ALL LANGUAGES to the English /login/ page. So I think my question is, "Do you guys know of a way to have that code above be mindful of if they are on biblicalevangelism.com or biblicalevangelism.com/es and "keep" the /es/ when redirecting to the login page?

My thanks ahead of time for even thinking this through with me! I'm kinda surprised other BuddyBoss/WPML Users haven't run into this already, but for the moment, I couldn't find anything. I did find what appeared to be a similar WPML Support Ticket here (https://wpml.org/forums/topic/login-page-not-redirecting-to-correct-language-in-buddyboss-2/) but couldn't get that function to do anything as you'll see in the video above.

IS THERE A SIMILAR EXAMPLE THAT WE CAN SEE?
Here is a screen recording of me demonstrating the issue: hidden link

WHAT IS THE LINK TO YOUR SITE?
biblicalevangelisml.com (biblicalevangelism.com/es)

January 25, 2024 at 12:13 am #15224245

Andreas W.
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

You can save the current language inside your function to a variable by using this hook:
https://wpml.org/wpml-hook/wpml_current_language/

It will return the language code of the active language.

Then set conditions for each language and change the returned URL accordingly.

// Get the current language code
$current_language = apply_filters('wpml_current_language', null);

// Check if the current language is English
if ($current_language == 'en') {
  // Do something for English
} else {
  // Do something for other languages
}
January 25, 2024 at 1:07 pm #15226224

calebW-2

Perfect! Thank you so much, Andreas! That was just what I needed.

Thank you!