Skip Navigation

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

Problem:
You are trying to translate words embedded in HTML tags within a .php template for a custom post type, which are not editable from the WordPress dashboard.
Solution:
If you're experiencing this issue, we recommend you try the following steps:
1. Wrap the strings in the gettext

__()

function. For example, replace:

echo '<h3 class="trustee-heading">Role</h3>';

with:

echo '<h3 class="trustee-heading">'.__('Role','themedomain').'</h3>';

Apply this procedure for all hardcoded strings you wish to make translatable.
2. Scan the theme or plugin from the WPML > Theme and plugins localization page where you updated the code.
3. Go to the WPML > String Translation page, search for the string, and add the translation.
For more detailed instructions, please visit our documentation on translating texts wrapped in gettext calls.

If this solution does not apply to your case, or if it seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please open a new support ticket at WPML 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 5 replies, has 0 voices.

Last updated by barjD-2 5 days, 3 hours ago.

Assisted by: Noman.

Author Posts
December 15, 2024 at 2:00 am #16514272

barjD-2

Background of the issue:
I am trying to translate a page that has words in HTML tags which are not editable from the WordPress dashboard. They are only editable in a .php template that controls the appearance of the page. The page is a custom post type.

Symptoms:
I am unable to translate words embedded in a custom template because they are not editable from the WordPress dashboard.

Questions:
How do I translate words embedded in HTML tags in a .php template for a custom post type?

December 15, 2024 at 9:35 am #16514619

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting WPML Support. For translating the hardcoded strings from PHP files, please try to follow the below steps:

1. Make sure to wrap the strings in the gettext __() function by replacing the below string:

echo '<h3 class="trustee-heading">Role</h3>';

With:

echo '<h3 class="trustee-heading">'.__('Role','themedomain').'</h3>';

From a php file. You may follow the same procedure for all hardcoded strings which you want to make translatable.

2. Scan the theme/plugin from WPML >> Theme and plugins localization page in which you update the code.

3. Go to the WPML >> String Translation page, search the string and add the translation.

Here is a doc for more details:
https://wpml.org/documentation/support/translating-the-theme-you-created/#wrap-all-texts-in-gettext-calls

Please let me know the results,
Thank you

December 16, 2024 at 3:41 am #16515549

barjD-2

Thank you very much for your fast reply.

I have adjusted the code per your sample.

I have also tried the e() function and tried using a different text domain with both the get text and e() function.

I make changes in the WordPress file editor.

After doing this, I click to save the file.

I get a message that the file was edited sucessfully.

I then go to Theme and plugins localization.

I select "Genesis" and "Monochrome Pro" and then I click on "Scan selected themes for strings"

I get a success message such as "Scan successful! WPML found 681 strings. They were added to the string translation table.
The following files were processed:"

I then click on WPML > String Translation

I scroll to the bottom of the page and click on "Translate texts in admin screens »"

I search for "Region"

The h3 tag does not come up.

I have attached screenshots of the steps described above so you can see the screens.

I looked at the documentation link you provided. However it seems to be about creating a new plugin and a lot more steps that we're not used to.

Are you able to help us find a solution to be able to translate these HTML tags?

Thank you again.

string search results after scanning theme 2024-12-15 at 7.23.32 PM.png
wpml-theme-string-scan-success-message 2024-12-15 at 7.31.55 PM.png
wpml-theme-string-scan-selection 2024-12-15 at 7.33.23 PM.png
code-by-wpml with e function genesis domain 2024-12-15 at 7.36.47 PM.png
code-by-wpml with get text function genesis domain 2024-12-15 at 7.22.59 PM.png
code-by-wpml 2024-12-15 at 7.26.09 PM.png
December 16, 2024 at 7:48 am #16516019

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for trying the steps and sharing the details. I noticed a couple of points:

1. Avoid using the _e() function when using echo. Instead, stick to the __() function as suggested in my earlier reply.

2. When searching for the text, use the WPML >> String Translation page directly, not the Admin Text Translation section.

Please try these adjustments and let me know the results.
Thank you

String translation.png
December 16, 2024 at 7:34 pm #16518720
barjD-2

Thank you very much. I had tried the e() function just in case it would work, when I couldn't get the original code to work.

Your solution does work, thank you.

I have another instance of the word "Roles:" which seems to come from the Genesis theme somewhere. It is not visible in a string search, even after I have scanned the theme and child theme to search for strings. I am not sure if this requires a new ticket, or if it can be resolved in this ticket, being that it is a similar issue.

Can you confirm?

I have attached screenshots to show what I mean.

Visible on this page: hidden link

New threads created by Noman and linked to this one are listed below:

https://wpml.org/forums/topic/unable-to-find-string-for-translation/

genesis-monochrome-entry-term-string-no-results 2024-12-16 at 11.27.41 AM.png
genesis-monochrome-entry-terms-string-not-translated 2024-12-16 at 11.27.00 AM.png
December 17, 2024 at 8:34 am #16520277

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Glad to hear the hardcoded string translation issue is solved. For searching the string for translation, it’s a different issue and will be handled separately as per our support policy. I've created a new ticket for this at: https://wpml.org/forums/topic/unable-to-find-string-for-translation/

If the hardcoded string translation issue is solved, please mark this ticket as resolved and we will continue working on the above ticket for it.

Thank you for your cooperation

December 17, 2024 at 8:11 pm #16523398

barjD-2

Very helpful support