Skip to content Skip to sidebar

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

Problem:
The client was preparing their theme for translation and needed to register hardcoded image alt attributes for translation with WPML. Since the images were hardcoded in the theme (not in the Media Library), they wanted the alt text to be translatable.

Solution:
We explained that any hardcoded string, including image alt tags, must be wrapped in a gettext function (e.g., __() or _e()) with a textdomain to be detected by WPML’s String Translation. For example:

<img src="image.jpg" alt="<?php echo __('My alt text', 'your-text-domain'); ?/>">

After making this change, WPML could register the string and the alt text was successfully translated.

For a complete guide on making hardcoded theme and plugin strings translatable—including how AI can simplify the translation workflow—see: Translate WordPress Themes and Plugins with AI.

Please note that this solution might be outdated or not applicable to your specific case. 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 the issue persists, 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 1 reply, has 0 voices.

Last updated by jeremiahH 8 months, 3 weeks ago.

Assisted by: Itamar.

Author Posts
March 20, 2025 at 5:51 pm #16841516

jeremiahH

Background of the issue:
We have not yet begun translation but are in the process of preparing the theme to grab hardcoded strings. We have a couple of images that are in the theme and we have added alt tags to them. I'm having difficulty registering them as a single string to be available for translation. I believe that if we have the image hardcoded in the theme, it will copy to new languages which is fine, we just want the alt text translated. These images are not in media, they are in the theme.

Symptoms:
Difficulty registering hardcoded image alt tags as a single string for translation.

Questions:
How can I register hardcoded image alt tags in the theme for translation using WPML?

March 23, 2025 at 10:35 pm #16849395

Itamar
WPML Supporter since 02/2016

Languages: English (English )

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

Hi,

You must wrap any hard-coded strings, including alt text, with a GETTEXT call. Please read about it in the following guide for developers.

https://wpml.org/documentation/support/how-to-use-gettext/

Please let me know if you have any further questions.

Please share your site's Debug information if you need further help with this issue. You can read about it here.

http://wpml.org/faq/provide-debug-information-faster-support/

Regards,
Itamar.

March 24, 2025 at 5:42 pm #16853612

jeremiahH

Thank you! I was able to grab the alt tag now.