Use CMS and Embed Codes to link PDFs according to Language

Hi guys,
I try to build a button which should link to pdfs from the CMS depending on which language site you are.

It works, BUT the first link it retrieves stays the same link for both courses. How can I make sure that the link is always based on the CMS item?

That’s the embed code for the button within the CMS item:


<a class="conditional-link" href="#">Flyer herunterladen</a>
<script>
  document.addEventListener("DOMContentLoaded", function() {
    var linkElements = document.querySelectorAll('.conditional-link');
    linkElements.forEach(function(linkElement) {
      if (window.location.pathname.includes('/ar')) {
        linkElement.href = '{{wf {&quot;path&quot;:&quot;flyer-arabisch&quot;,&quot;type&quot;:&quot;FileRef&quot;\} }}';
      } else {
        linkElement.href = '{{wf {&quot;path&quot;:&quot;flyer&quot;,&quot;type&quot;:&quot;FileRef&quot;\} }}';
      }
    });
  });
</script>

Here is my site Read-Only: LINK