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 2 replies, has 2 voices.

Last updated by Bruno 4 months, 3 weeks ago.

Assigned support staff: Bruno.

Author Posts
May 21, 2019 at 1:37 am #3850809

mattT-9

I am redirecting the wp-login page to a custom login page using the function.php to /login/. I provided the redirect php below that works. However, I want the below code to work for english and a different login url for spanish (hidden link).

How can I do that?

Link to a page where the issue can be seen: hidden link . Currently will redirect all languages to /login/

/* Main redirection of the default login page */
function redirect_login_page() {
$login_page = home_url('/login/');
$page_viewed = basename($_SERVER['REQUEST_URI']);

if($page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {
wp_redirect($login_page);
exit;
}
}
add_action('init','redirect_login_page');

May 21, 2019 at 1:51 am #3850841

mattT-9

Or the full wp-login redirect code is:

function pt_redirect_login_page() {

$login_page = home_url( '/login/' );
$page_viewed = basename($_SERVER['REQUEST_URI']);

if( $page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {
wp_redirect($login_page);
exit;
}
}
add_action('init','pt_redirect_login_page');

function pt_login_failed() {
$login_page = home_url( '/login/' );
wp_redirect($login_page . "?login=failed");
exit;
}
add_action( 'wp_login_failed', 'pt_login_failed' );

function pt_verify_username_password( $user, $username, $password ) {
$login_page = home_url( '/login/' );
if( $username == "" || $password == "" ){
wp_redirect($login_page);
exit;
}
}
add_filter( 'authenticate', 'pt_verify_username_password', 1, 3);

May 21, 2019 at 4:17 am #3851803

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for contacting us. First, you should know the current language (using the const ICL_LANGUAGE_CODE) to then set the correct URL. For example:

	$login_page = home_url( '/login/' );
	if( ICL_LANGUAGE_CODE === 'es' ) {
		$login_page = home_url( '/es/iniciar-sesion/' );
	}

As this is a custom feature, unfortunately, this is beyond the scope of our support.

We have a list of WPML hooks that can help you develop such feature, which can be seen in the links below:

- https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference

If you prefer, you can contact one of our certified partners who can develop small to large features for your site: http://wpml.org/documentation/support/wpml-contractors/

Please, let me know if I can help with any other questions you may have about it. I'll be happy to help.

Thank you.