Skip Navigation

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

Problem:
The client wants the author bio link in the recipe card to redirect to the appropriate language version of the 'about-me' page, depending on the language the visitor is viewing the recipe card in. The current setup only redirects to the English version, even when the site is switched to Dutch.

Solution:
1. We recommend enabling the translation of the author by navigating to WPML > String Translation > More Options and checking the option to translate users.
2. If the author link is not a standard WordPress author page and is instead implemented using a custom template or page, we suggest using the wpml_object_id hook to adjust the URL based on the current language. This hook allows for the translation of post IDs, ensuring the correct page is served for each language.

Here is an example of how you might use the hook:

<?php<br />$translated_post_id = apply_filters( 'wpml_object_id', $post_id, 'page', true );<br />$translated_post_url = get_permalink( $translated_post_id );<br />return $translated_post_url;<br />?>

3. Alternatively, you can register the URL as a string and translate it using the wpml_register_single_string hook, or create a conditional statement that checks the current language and returns the appropriate URL.

For more information on WPML hooks, you can visit our WPML hooks reference and the wpml_object_id hook documentation.

Please note that we do not provide fixes for custom code as per our support policy. If you require custom assistance beyond the scope of our support, we recommend contacting one of our certified partners from this link.

If this solution does not seem relevant to your issue, please open a new support ticket here.

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

Last updated by Itamar 1 year, 4 months ago.

Assisted by: Itamar.

Author Posts
December 7, 2023 at 11:52 am #15016283

Sean

Tell us what you are trying to do? Have the author bio in the recipe card link to the appropriate language depending on what language the visitor is viewing the recipe card.

Is there any documentation that you are following? None that we can find.

Is there a similar example that we can see? Don't think so.

What is the link to your site? hidden link

Basically, go to any recipe in English, scroll or jump to the recipe card, then click on 'Author' (Sabine) You should be taken to the 'about-me' page. But when you switch to Dutch and click on the author bio in the recipe card it still takes you to the English version of the bio and not the Dutch version which is 'over-mij'.

Any ideas?

December 8, 2023 at 1:26 pm #15026015

Sean

I managed to add code to functions.php, but it still only goes to the English '/about-me/', and nl/about-me/

So, how can we make the author link go to /nl/over-mij/ when the visitor is looking at any page in Dutch?

December 8, 2023 at 6:08 pm #15027633

Sean

I have now added a 301 redirect in htaccess. nl/about-me now redirects to nl/over-mij

I just want to be sure this is good for SEO.

December 10, 2023 at 3:17 pm #15031557

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.

It depends on how you implemented that author link. It does not seem to be a normal WordPress post author page and it seems to be an Elementor template.

If it is a normal Author, you can enable the author's translation by going to WordPress Dashboard > WPML > String translation > More Options and enable the translation of the users.

But for your case I am not sure.

I did a search in Google and found this article when it comes to 301 redirect and SEO impact:

elegantthemes.com/blog/wordpress/do-301-redirects-impact-seo

Thanks.

hidden link

December 10, 2023 at 8:02 pm #15032035

Sean

Hi there,

Just to clarify what I've done. This is the custom code now in functions.php:

// Link author name to about page
add_filter( 'author_link', 'my_author_link' );
function my_author_link() {
return home_url( 'about-me/' );
}

And this is what's in .htaccess:

Redirect 301 /nl/about-me hidden link

The reason for doing all this is it is only a single author website. By default WordPress sends clicks on all author links at the top of posts/pages to the author archives, or the home page if you set it to with plugins like Yoast, otherwise this is apparently a duplicate content issue with single author sites.

So, we are now sending visitors to where we really want them to go, in a bit of a round about way, in that /about-me and /nl/about-me both went to the same place, hence the 301 which fixed that problem, but I have to wonder if this is something WPML can make happen by sending visitors to either /about-me or /nl/over-mij directly.

Yes, I found that setting for translating author user string translating, but that doesn't seem to help with this custom redirect.

It is a regular page made with a Divi template, which is what we've used to make every other page on the site.

I hope this clarifies things better? Or maybe the attached screenshot will show what I'm trying to fix. Look at the bottom of the image, at where they author link would take you if it wasn't for the 301:

Screenshot 2023-12-10 at 21.00.51.jpg
December 11, 2023 at 8:27 pm #15040665

Itamar
WPML Supporter since 02/2016

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

I'll continue to help with this issue.

You may want to try incorporating a WPML hook into your code to make it work. You can see all WPML's hooks here.

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

The wpml_object_id hook may be the one you are looking for.

https://wpml.org/wpml-hook/wpml_object_id/

I hope this information will help you solve the problem and illuminate the need for a 301 redirection.

Regards,
Itamar.

December 12, 2023 at 4:36 pm #15048351

Sean

Hi there,

Thanks for getting back to me. I must confess, I know what hooks are but I have never worked with them until now. I tried the one suggested after modifying as I thought I had to but it didn't work.

Also, what I am trying to do isn't very unique, it's a universal code that many use to direct the author link to a page of choice.

With that said, do you perhaps have any further suggestions on how I can get this to work to the point I will not need the 301?

December 13, 2023 at 10:30 am #15052871

Itamar
WPML Supporter since 02/2016

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

I'm consulting our second-tier supporters about this case. I'll update you here once I have their reply.

Regards,
Itamar.

December 13, 2023 at 10:36 am #15052995

Sean

Thank you for the update. One other point of clarification; as in the title, this isn't about the WP Recipe Maker plugin anymore, when I initially thought it was. It is about the Author link at the top of posts. The WP Recipe plugin gets its author link from the same place, that's the only connection.

December 13, 2023 at 10:59 am #15053459

Itamar
WPML Supporter since 02/2016

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Yes, I noticed the problem is not specific to the Recipe post type.

Here is the answer from our second-tier supporter.

Since he is using: return home_url( 'about-me/' );
He should probably add a call to localize it first.

Because his URL is "example.com/second_language/about-me," and this is calling the first language (English) page from the second language. The redirect is normal.

He can either register this as a string and translate it - using our hooks or create a simple clause first, getting the current language and returning different values by the language code.

This is the link to the wpml_register_single_string hook.
https://wpml.org/wpml-hook/wpml_register_single_string/

We have extensive guides and information for developers here.
https://wpml.org/documentation/support/

We are not providing fixed for custom code. Please check our support policy here.
https://wpml.org/purchase/support-policy/

If you show us where our hooks or API fail to work as expected, we will check and correct it if needed.

Otherwise, if you need further help with what you are trying to achieve, I would suggest you consider contacting one of our certified partners from this link:

https://wpml.org/contractors/

Before doing so, please have a look here:

https://wpml.org/documentation/about-wpml-contractors/what-type-of-work-you-can-expect-from-contractors/

With our contractors, you might get the custom assistance you need to get on with your project.

Regards,
Itamar.

December 13, 2023 at 3:28 pm #15056679

Sean

I am marking this as not fully resolved, at least I think have enough info now to get it resolved as it would indeed seem this is now out of the scope of WPML support.

Thanks again to all for the help so far.