Skip Navigation

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 2 voices.

Last updated by Bobby 1 month, 2 weeks ago.

Assigned support staff: Bobby.

Author Posts
April 22, 2021 at 11:05 am #8599913

julianoA

Dear Sirs,

I've added some custom code in my child theme in functions.php.

How can I add a string to the current code so that I can translate the text "Таблица с размер" as well as have the link go to another page for the second language.

------------

function my_extra_button_on_product_page() {
global $product;
echo '<a class="size-chart" href="hidden link" ><img class="alignnone size-full wp-image-8985" />Таблица с размери</a>';
}

April 23, 2021 at 6:52 am #8606543

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hello,

The text must be wrapped in a gettext call, please review the following documentation and let me know your results.

https://wpml.org/documentation/support/enabling-text-translation-for-themes-not-compatible-with-wpml/

April 23, 2021 at 7:08 am #8606631

julianoA

Hi Bobby,

I already read the doc and ran the code but I keep getting an error from the functions file.

April 23, 2021 at 9:49 pm #8612183

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Thank you for updating me!

If possible share the code you are adding in the functions.php with me or even better a copy of your functions.php file using a file sharing service such as dropbox, wetransfer,etc

That way I can see if something needs to be changed.

April 25, 2021 at 10:14 am #8617397

julianoA

Hi Bobby,

This is the code I have and want to be able to edit the text and link for my second language:

function my_extra_button_on_product_page() {
global $product;
echo '<a class="size-chart" href="#" ><img class="alignnone size-full wp-image-8985" />Таблица с размери</a>';
}

April 26, 2021 at 11:13 pm #8629583

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hello,

The code you provided me is not wrapped in a gettext call

Here is the code:

function my_extra_button_on_product_page() {
	global $product;
	echo '<a class="size-chart" href="#" ><img class="alignnone size-full wp-image-8985" />'. esc_html__('Таблица с размери','my-text-domain') .'</a>';
	}

Notice that it's wrapped in a gettext call.

Please note that custom work falls outside the scope of our support within this forum, if further adjustments are required, please review the official documentation here.
https://wpml.org/documentation/support/enabling-text-translation-for-themes-not-compatible-with-wpml/

April 28, 2021 at 1:44 pm #8645019

julianoA

Bobby,

Thank you so much for the assistance.
Everything works great and now I understand how to add strings to text, but I am not able to add a string to the link. The code keeps giving me errors.
Can you let me know which code from the documentation I must use in order to not get a error.

April 28, 2021 at 4:05 pm #8646285

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Glad to hear that!

What do you mean by a string to the link? If possible share some more information with me.

This is not for the same string right?

April 28, 2021 at 4:23 pm #8646377

julianoA

It's for the same piece of code.
I have a href="#" tag and I want to have the link appear in the string's dashboard so I can have it point to another page for the second language.

function my_extra_button_on_product_page() {
global $product;
echo '<a class="size-chart" href="#" ><img class="alignnone size-full wp-image-8985" />'. esc_html__('Таблица с размери','my-text-domain') .'</a>';
}

April 29, 2021 at 5:19 pm #8656617

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hello,

While it is possible to wrap the link in the href (you need to break down the structure just like I already did with the other wrap), please review the following documentation which is a better option for hardcoded links.

https://wpml.org/documentation/support/creating-multilingual-wordpress-themes/hard-coded-theme-link

Please do note that custom work is beyond the scope of this support, if possible try the above solution and let me know your results.

The topic ‘[Closed] Create a string in functions php’ is closed to new replies.