Skip Navigation

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

Problem:
The client needed to change and translate a URL in the PHP code from the

functions.php

file, specifically within an action hook that outputs a contact button.

Solution:
We recommended using the gettext function to make the string translatable. We provided step-by-step instructions:
1. Replace the hardcoded URL in the PHP code with the

__()

function and include the text domain.
2. Rescan the theme for strings using WPML's String Translation.
3. Translate the URL in WPML > String Translation.

Here is the modified code snippet:

add_action('ava_main_header', function() {
$output = __("<div class='av-cta-button av-desktop-hid av-tablet-hide av-button'><a href='https://outdoorpsycholoogleiden.nl/contact/'>Contact</a></div>", "your-text-domain");
echo $output;
}, 10);

For more information, we provided links to the relevant documentation:

If this solution does not apply to your case, or if it seems outdated, we encourage you to open a new support ticket. We also highly recommend checking related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. For further assistance, please visit 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.

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Mihai Apetrei 1 year, 4 months ago.

Assisted by: Mihai Apetrei.

Author Posts
January 31, 2024 at 7:48 pm #15251647

joostL-3

Hi,

I want to change/translate the url in the php code below from functions.php from 'hidden link' (dutch page) to 'hidden link'
(english page).

add_action('ava_main_header', function() {
$output = '<div class="av-cta-button av-desktop-hid av-tablet-hide av-button">hidden link">Contact</div>';
echo $output;
}, 10);

Can you please help me with this?

Regards,

Joost

January 31, 2024 at 11:58 pm #15252397

Mihai Apetrei
WPML Supporter since 03/2018

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hi Joost. Sure!

Internationalization needs to be used (gettext) in order to get the strings translatable.

Please take a look here:

- https://wpml.org/documentation/support/translating-the-theme-you-created/#get-started-understanding-gettext-text-domains-and-domain-paths

and here:

- https://codex.wordpress.org/I18n_for_WordPress_Developers

I think this might work (make sure that you create a full website backup first or make these changes from inside a file manager:

add_action('ava_main_header', function() {
$output = __("<div class='av-cta-button av-desktop-hid av-tablet-hide av-button'><a href='<em><u>hidden link</u></em>;", "your-text-domain");
echo $output;
}, 10);

Now, try to re-scan the theme:
https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/#scan-the-theme-or-plugin

All the html, together with the URL, should show up in WPML > String Translation so that you can translate it.

Please let me know how things go.

Mihai Apetrei

February 1, 2024 at 9:26 am #15253400

joostL-3

It worked! Thank you very much!

Joost