Indice della documentazione

Cookie solution ›

How to use the Cookie Law Solution in a multilingual WordPress site


To manage multilingual sites with WordPress you can use the WPML plugin. WPML allows you to create multiple language versions of your site. Here’s how:

1. You must first generate the iubenda code that will output the banner to the site by following the instructions in this guide.

2. Each language has its own dedicated code snippet that must be inserted into the site’s html, as described in detail in this guide. The correct code is generated when you click on Enable/Configure Cookie Policy for each language version of the privacy policy:

cookie policy in various languages: settings

3. The code – which is similar to that in the example below – should be inserted before the closing of the HEAD tag.

<script type="text/javascript">
  var _iub = _iub || [];
  _iub.csConfiguration = {
    cookiePolicyId: XXxxXX,
    siteId: XXXXX,
    lang: "fr"
  };
  (function (w, d) {
    var loader = function () { var s = d.createElement("script"), tag = d.getElementsByTagName("script")[0]; s.src = "//cdn.iubenda.com/cookie_solution/iubenda_cs.js"; tag.parentNode.insertBefore(s, tag); };
    if (w.addEventListener) { w.addEventListener("load", loader, false); } else if (w.attachEvent) { w.attachEvent("onload", loader); } else { w.onload = loader; }
  })(window, document);
</script>

As you can imagine, each language has its own code, the difference is in this part of the snippet lang: "fr".

How to integrate the script of the iubenda cookie banner with WPML

4A. Use the WordPress plugin by iubenda

You can use our WordPress plugin that will detect WPML and offer forms to copy-paste the above iubenda scripts.

iubenda_wpml_en.png

4B. If you don’t want to use the WordPress plugin

Another way of making this work would be a full Javascript solution as suggested by Mirco in this gist.

<!-- as suggested by https://gist.github.com/mircobabini/de33dab69ca7598f39b6 -->
<!-- replace 000001 with the site_id from your specific iubenda embed code -->
<!-- replace 000002 with the policy_id from your EN iubenda embed code -->
<!-- replace 000003 with the policy_id from your IT iubenda embed code -->

<script type="text/javascript">
var lang_id = jQuery('html').attr('lang').split('-')[0]
  , site_id = 000001; // site_id from iubenda embed code
switch( lang_id ){
  case 'en':
    var policy_id = 000002; // policy_id from iubenda embed code EN
    break;
  case 'it':
    var policy_id = 000003; // policy_id from iubenda embed code IT
    break;
  // case 'other language code' ...
}
var _iub = _iub || [];
_iub.csConfiguration = {
  cookiePolicyId: policy_id,
  siteId: site_id,
  lang: lang_id
};
(function (w, d) {
  var loader = function () { var s = d.createElement("script"), tag = d.getElementsByTagName("script")[0]; s.src = "//cdn.iubenda.com/cookie_solution/iubenda_cs.js"; tag.parentNode.insertBefore(s, tag); };
  if (w.addEventListener) { w.addEventListener("load", loader, false); } else if (w.attachEvent) { w.attachEvent("onload", loader); } else { w.onload = loader; }
})(window, document);
</script>

Once the code has been generated by iubenda in the manner described above, it needs to be added in the HEAD section in all of the pages of the site.


Hai ancora domande?

Visita il nostro forum di supporto Scrivici via email