Skip to content Skip to sidebar

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

Problem:
If you're experiencing an issue where the language switcher only shows the default language on author profiles, even when there are no posts or other information translated into all languages, we have a solution for you.
Solution:
Firstly, ensure that the translation preference for Posts is set to display the default language when a translation is not available. You can do this by navigating to WPML > Settings > Post Type Translation and adjusting the setting for "Posts" to "Translatable - use translation if available or fallback to default language".

Alternatively, you can use a custom code approach. We've provided a code snippet that you can add to your theme's

functions.php

file. This code will adjust the Language Switcher on the Author page to show additional languages, regardless of whether the author's posts have been translated.

Here is the code snippet:

function author_language_switch($w_active_languages ) {
	if(is_author() && count($w_active_languages) == 1) {
		$user_id = get_the_author_meta('ID');
		$author_url = get_author_posts_url($user_id);
		$languages = apply_filters( 'wpml_active_languages', NULL, array( 'skip_missing' => 0 ) );
		foreach($languages as $language) {
			$languages[$language['code']]['url'] = apply_filters( 'wpml_permalink', $author_url, $language['code']);
		}
		return $languages;
	}
	return $w_active_languages;
}

Remember to also translate the author's biographical information as described in our guide on translating user meta information with WPML.

If this solution doesn't seem relevant to your situation, please don't hesitate to open a new support ticket with us for personalized assistance. You can do so by visiting our 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 7 replies, has 3 voices.

Last updated by Prosenjit Barman 1 year, 12 months ago.

Assisted by: Prosenjit Barman.

Author Posts
December 15, 2023 at 10:04 am #15070953

manuelO-2

On my website I display a list of all registered users and all people have access to their profiles. The problem is that the language switcher only shows the default language. I am using the WordPress full site editor.

December 16, 2023 at 2:17 pm #15077501

Christopher Amirian
WPML Supporter since 07/2020

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

I will add the first reply before this ticket is assigned to one of my colleagues.

If I understood correctly, you want to translate the default author's of WordPress.

If so, Please go to WPML->String Translation->More Options->edit and select the author's role then it should display in String Translation:

hidden link

If you have another ruse-case I'd appreciate it if you can give more context on how you have implemented the feature.

Thanks.

December 16, 2023 at 4:46 pm #15077663

manuelO-2

What I need is to translate the author's page.

Actually the page is already translated properly, the problem is that only one of the two languages is displayed in the language switcher.

For example, if I go to /author/prueba/ it shows me the author's page in Portuguese, but it doesn't give me the possibility to change the language in the language switcher. The same happens if I enter /en/author/prueba/, in this case it shows me the translatable information in English but I don't have the possibility to change the language.

December 18, 2023 at 1:06 pm #15084421

Prosenjit Barman
WPML Supporter since 03/2023

Languages: English (English )

Timezone: Asia/Dhaka (GMT+06:00)

Hi There,
Thank you for the update.

Please note that the language switcher is designed to display and function correctly for Authors who have posts that are translated into other available languages. If an author hasn't posted anything or has only posted in one language, the language switcher will not appear on that Author's profile.

However, if you wish for the Language switcher to display languages and function correctly irrespective of whether the author's post has been translated or not, you can try the suggestion mentioned in the response below.

- https://wpml.org/forums/topic/wpml-doesnt-detect-wp-templates-as-translated/#post-14785493

Please let me know if that helps to solve the issue or if you need further assistance in this matter. I will be happy to help.

Best regards,
Prosenjit

December 18, 2023 at 1:09 pm #15084461

manuelO-2

You send me a link to a private ticket. Only the author can view this ticket.

December 19, 2023 at 8:29 am #15089555

Prosenjit Barman
WPML Supporter since 03/2023

Languages: English (English )

Timezone: Asia/Dhaka (GMT+06:00)

Hi There,

Please note that ticket visibility is restricted to logged-in users only. Make sure you are logged into your WPML.ORG account to view them. I can confirm that the ticket is not marked as private.

Let me know the update. I will be happy to help if you need further assistance in this matter.

Best regards,
Prosenjit

December 19, 2023 at 9:49 am #15090501

manuelO-2

I'm not stupid. I know exactly what I see and this ticket is private, I can assure you.

I attach a screenshot. As you can see, I am logged into my account and the ticket is private.

private.jpg
December 20, 2023 at 3:42 am #15097425

Prosenjit Barman
WPML Supporter since 03/2023

Languages: English (English )

Timezone: Asia/Dhaka (GMT+06:00)

Hi There,

I'm sorry if my earlier message seemed dismissive or disrespectful - that was not my intention. I didn't mean to question your intelligence or your grasp of the situation. The suggestion to check by logging into your account was based on the common practice of many users attempting to access links directly from their emails. I hope you can understand.

Since you can't access the ticket, I've included the particular response below.


The Language Switcher should only display other languages in the Author template if the Author has a post that has been translated into those languages. If the post is not translated, even the default language will not appear in the language switcher.

Now, this can be solved in two ways:

1) Setting up the translation preference for the Posts to display the default in case the translation is not available: Please navigate to WPML > Settings > Post Type Translation. Here, adjust the translation preference for "Posts" to "Translatable - use translation if available or fallback to default language". This setting ensures that the default language post is shown when a translation is absent, allowing the language switcher to consistently display alternative languages on both the post and author pages. This method is recommended.

2) Code Approach: Using WPML's hooks and filters, you can adjust the Language Switcher on the Author page to show additional languages, regardless of whether the author's posts have been translated into those languages.

Here's the Hook and Filter reference guide: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

While our support platform typically doesn't assist with custom coding, I'm providing you with a code snippet. This code is designed to hide languages in the language switcher on an Author's page if they haven't published any posts. The languages will be displayed only if the Author has at least one post, regardless of whether the post is translated or not.

Please copy the code from here[ hidden link ] and past it in the functions.php file.

If you're using this code, make sure that a description is added in the Author Profile(you can add that by going to Users > Profile → About the user → Biographical Info), and the description is also been translated.

Check this guide to learn more about translating the Meta information of the users: https://wpml.org/documentation/getting-started-guide/string-translation/translating-user-meta-information-with-wpml/

If you need further assistance with the custom code, you can hire a contractor specialized in customizing WPML, from here: https://wpml.org/contractors/

I hope it helps. Please let me know if you need further assistance in this matter. I will be happy to help.

Best regards,
Prosenjit

December 20, 2023 at 9:46 am #15099913

manuelO-2

Ok, thanks for the answer.

By itself it serves someone in the future, to always show the active languages in the authors' profiles, regardless of there is no post or any other information translated to all languages, the code can be the following.

function author_language_switch($w_active_languages ) {
if(is_author() && count($w_active_languages) == 1) {
$user_id = get_the_author_meta('ID');
$author_url = get_author_posts_url($user_id);
$languages = apply_filters( 'wpml_active_languages', NULL, array( 'skip_missing' => 0 ) );
foreach($languages as $language) {
$languages[$language['code']]['url'] = apply_filters( 'wpml_permalink', $author_url, $language['code']);
}
return $languages;
}
return $w_active_languages;
}

A greeting.