Base URL in HTML Embed Code

Hi there,

I have a case where I want to include my website’s current base URL as a field inside of the HTML embed code. This is due to integrating Disqus into my site which requires that I attach a canonical URL to some variable, so it would not be ideal to place a relative URL.

Right now for testing, I have it set as my staging site <staging_site> and that means I would have to manually go through all the embeds to replace them with the live site base URL when publishing the production site.

How can I reference the base URL from the embed code? I can’t seem to find any resources on this anywhere.

Thanks in advance!

Hey @ChengMan

What’s your use case? Are you using this on static or CMS generated pages? If its the latter, you can do as follows;

var disqus_config = function () { = window.location.href; = 'YOUR-CMS-PAGE-SLUG';

  (function() {
    var d = document, s = d.createElement('script');
    s.src = '';
    s.setAttribute('data-timestamp', +new Date());
    (d.head || d.body).appendChild(s);
1 Like

Hey, @AlexManyeki I’m using this on a CMS generated page. Your solution works great, thank you!

1 Like

Welcome @ChengMan :slightly_smiling_face: