This thread is resolved. Here is a description of the problem and solution.
Problem:
The client is trying to translate customized fields using WPML but encounters an issue where the translations do not appear on the frontend. The client used a custom hook and registered labels to WPML, translating them successfully. However, despite following documentation and using code examples, the translations are not visible on the frontend.
Solution:
1. Ensure the text domain is correct. According to WordPress documentation, the text domain must use dashes, be lowercase, and have no spaces.
2. When using variables in translated strings, use the
printf()
function instead of echoing the variable directly. For example, change:
<p id="popup-title"><?= $popuptitle ?></p>
to:
<p id="popup-title"><?php echo __('Subscribe Now, Save 10%', 'storefront') ?></p>
After making these changes, re-scan the strings in the child theme, translate the string, and check if the translation displays on the frontend.
3. If using a custom text domain like "popup", register it with the following function in your theme's
functions.php
file:
add_action( 'after_setup_theme', function() { load_theme_textdomain( 'popup', get_template_directory() . '/languages' ); } );
Refer to the WordPress documentation on loading a text domain for more details.
If this solution does not resolve your issue or seems outdated, we recommend opening a new support ticket. We also highly suggest 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. 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.
This topic contains 1 reply, has 0 voices.
Last updated by 1 week, 2 days ago.
Assisted by: Long Nguyen.