Skip Navigation

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

Problem:
Want to include a javascript snippet on a specific language

Solution:
The task mentioned should be achievable with a code implementation. Before adding the code, you'll need to determine the current language of your website. Fortunately, WPML provides a hook for this purpose: https://wpml.org/wpml-hook/wpml_current_language/.

Here's an example of how you can use this hook to apply code for a certain language:

// Get the current language
$current_language = apply_filters( 'wpml_current_language', NULL );
 
// Check if the current language is the desired one
if ( $current_language === 'your_desired_language_code' ) {
    // Add your code here to be applied for the specific language
    ?>
    <script>
        // Your script code goes here
    </script>
    <?php
}

Please replace `'your_desired_language_code'` with the language code you want to target. This way, the code will only be executed when the current language matches the specified language code.

Relevant Documentation:
https://wpml.org/contractors/

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.

Our next available supporter will start replying to tickets in about 2.90 hours from now. Thank you for your understanding.

This topic contains 2 replies, has 2 voices.

Last updated by pernilleL 9 months, 4 weeks ago.

Assisted by: Shekhar Bhandari.

Author Posts
June 30, 2023 at 9:01 am #13921873

pernilleL

My client has started using Activecampaign for e-mail newsletters, and want to add a pop-up to the homepage of their website. However, the newletter is only going to be in Danish, so it makes no sense to show the pop-up on the English version of their website.

Their SEO agency has asked me to place a <script src> code snippet for the sign-up pop-up in the website body-tag. Now, I would like to NOT include this snippet on the English version. Do you know if there is any way around this?

The site uses the Divi-builder, and I have checked both in your documentation and the documentation from Elegant Themes, but didn't seem to manage to find an example or an answer.

The website is hidden link

Thanks for any and all help.

July 3, 2023 at 5:41 am #13930205

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Greetings,

Thank you for reaching out to WPML support! I'm excited to help you with your question.

The task you mentioned should be achievable with a code implementation. Before adding the code, you'll need to determine the current language of your website. Fortunately, WPML provides a hook for this purpose: https://wpml.org/wpml-hook/wpml_current_language/.

Here's an example of how you can use this hook to apply code for a certain language:

// Get the current language
$current_language = apply_filters( 'wpml_current_language', NULL );

// Check if the current language is the desired one
if ( $current_language === 'your_desired_language_code' ) {
    // Add your code here to be applied for the specific language
    ?>
    <script>
        // Your script code goes here
    </script>
    <?php
}

Please replace `'your_desired_language_code'` with the language code you want to target. This way, the code will only be executed when the current language matches the specified language code.

Please note that while I can provide guidance and assistance with code examples, troubleshooting and further customization of custom code implementations fall outside the scope of our support.

If the provided code doesn't resolve the issue or meet your specific requirements, it may be necessary to seek the assistance of a custom contractor or developer who can offer tailored solutions to your needs. https://wpml.org/contractors/

Look forward to your reply.

Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.