How to display the content depending on the site language

How it works

You can segment the content and display particular blocks only to the users viewing the page in certain languages via a custom HTML code. You may use an existing solution or write your own code.

How to get it

Using an existing solution

  1. Go to Publisher Account > Site Builder.
  2. In the Header block, set up the Translations component.
  3. Select the language to hide particular blocks for.
  4. Insert the following code to the Custom code block:

Copy
Full screen
Small screen
<script>
  (function () {
    var blockArray = [
      {
        blockName: '.block--packs',
        blockNumber: 0
      },
      {
        blockName: '.block--description',
        blockNumber: 0
      }
    ];

    function removeBlock() {
      setTimeout(function () {
        blockArray.map(function (block) {
          return document.querySelectorAll(block.blockName)[block.blockNumber];
        })
          .forEach(function (element) {
            element && element.remove();
          });
      }, 0);
    }

    removeBlock();
  })();
</script>

  1. In the blockArray array, modify the following parameters for each block you want to hide from users for the chosen language:
    1. blockName — the name of the CSS class of the block. Possible options are:
      • .block--header (the Header block)
      • .block--hero (the Call to action block)
      • .block--html (the Custom code block)
      • .block--packs (the Packs block)
      • .block--description (the Description block)
      • .block--gallery (the Gallery block)
      • .block--requirements (the System requirements block)
      • .block--faq (the FAQ block)
      • .block--embed (the Social media widgets block)
      • .block--news (the News block)
      • .block--footer (the Footer block)
    2. blockNumber — the sequence number of the block. Minimum value is 0.
  2. Click Preview to see your changes.

Watch the tutorial video for this instruction:


Writing your own code

If you want to use your own code:

  1. Go to Publisher Account > Site Builder.
  2. Insert the code to the Custom code block.
  3. Click Preview to see your changes.

Was this article helpful?
Thank you!
Is there anything we can improve? Message
We're sorry to hear that
Please explain why this article wasn't helpful to you. Message
Thank you for your feedback!
We'll review your message and use it to help us improve your experience.

Continue reading