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 1.92 hours from now. Thank you for your understanding.

This topic contains 2 replies, has 2 voices.

Last updated by Puntorosso 1 year ago.

Assigned support staff: Bruno.

Author Posts
September 29, 2018 at 9:22 pm #2775805

Puntorosso

It would be nice if WMPL would have "Codes" fields in settings, where we could insert header/body/footer scripts like Google Analytics.

This fields should be available for any active language.

This way we could start a different script for any language that has been selected in front-end, and it's especially useful when we have a different domain/language.

I know that it's possible to achieve the same using if statements in php, but this would be a cleaner and comfortable way.

October 2, 2018 at 2:22 am #2779975

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for contacting and suggestion.

I can forward your ticket to our developers so they can check this out. At the moment, however, you can use the "Insert Headers and Footers" plugin (https://wordpress.org/plugins/insert-headers-and-footers/).

Then in WPML > Settings > Custom XML Configuration, insert these lines:

<wpml-config>
    <admin-texts>
        <key name="ihaf_insert_header" />
        <key name="ihaf_insert_footer" />
    </admin-texts>
</wpml-config>

By following these steps, you should be able to translate the content into WPML > String Translation. By following the steps above, this should work correctly.

Please, let me know if I can help with any other questions you may have. I'll be happy to help.

Thank you.

October 2, 2018 at 9:55 am #2780957

Puntorosso

Thanks for the tip.

Being a Toolset user I used another approach.
I created 2 custom fields in Types ("Header Script" and "Footer Script"), and inserted this code in functions.php

// insert Javascript Custom Field in header
function child_theme_head_script() {

echo (get_post_meta( get_the_ID(), 'wpcf-header-script', true));

}
add_action( 'wp_head', 'child_theme_head_script' );

// insert Javascript Custom Field in footer
function child_theme_foot_script() {
		
echo (get_post_meta( get_the_ID(), 'wpcf-footer-script', true ));
	
	}
add_action( 'wp_footer', 'child_theme_foot_script' );

Now I simply translate this fields and it works.
As an additional advantage I can insert any script in a single post/page.

Best