Iubenda logo
Start generating

Documentation

Table of Contents

How to Use the Privacy Controls and Cookie Solution in a Multilingual WordPress Site

To manage multilingual sites with WordPress, you can use plugins like WPML or Polylang. They allow 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. You can enable your cookie policy on the policy edit page, on the bottom right: [Your website] > Privacy and Cookie Policy > Edit

    Activate cookie policy

    The correct code is generated when you click on “Activate cookie policy”:

    Activate cookie policy
  3. Now, simply go to the Embed page by clicking on the “Manage and Embed” link above your website name. This will take you back to the site flow/overview page of your dashboard. Click on the <>Embed button under Privacy Controls and Cookie Solution to head to the embed section. Once there, you’ll find your banner embed code.

    If you’ve generated your policies in more than one language, there will be language tabs visible for each language you’ve activated for the policy. Each tab contains the code specific to the particular language of that policy:

    Cookie Solution language tabs

    Simply click on the tab for the language you want and copy the corresponding cookie banner/consent banner code.

  4. 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 = {
        "lang": "en",
        "siteId": XXXXXX, //use your siteId
        "cookiePolicyId": YYYYYY, //use your cookiePolicyId
        "banner": {
            "position": "top"
        }
    };
</script>
<script type="text/javascript" src="//cdn.iubenda.com/cs/iubenda_cs.js" charset="UTF-8" async></script>

As mentioned, each language has its own code, the main difference being the id it’s pointed at.

How to integrate the script of the iubenda cookie banner/consent banner with the WordPress plugin

You can use our WordPress plugin that automatically detects the multilingual plugin you’re using (WPML and Polylang) and offer forms to copy-paste the above iubenda scripts:

Custom integration

If you don’t want to use the WordPress plugin, another way of making this work is a full JavaScript solution, as suggested by Mirco in this gist. Here’s an updated version of his approach:

*Note: you can use this method to integrate our Privacy Controls and Cookie Solution into every multilingual website.

<!-- 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 = {
        "lang": lang_id,
        "siteId": site_id,
        "cookiePolicyId": policy_id,
        "banner": {
            "position": "top"
        }
    };
</script>
<script type="text/javascript" src="//cdn.iubenda.com/cs/iubenda_cs.js" charset="UTF-8" async></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.

See also