URLs escaped when incuded in script tags

Hello there,
I’m trying to add a .Site.BaseURL in a script but at render time, the base URL always include escaped slashes that are clearly making the script failing.

I’ve tried to convert into a string, using the safeHTML function and few other without success.
Example {{ printf "%s" .Site.BaseURL | safeHTMLAttr }}

<script type="application/ld+json">{
    "@context": "https://schema.org",
    "@type": "WebSite",
    "url": "{{ .Site.BaseURL | absURL }}",

As soon as the value is printed outside the script, the correct value is shown.
Any idea of what I’m missing here?

Do not encapsulate the baseURL value in quotes.

<script type="application/ld+json">{
  "@context": "https://schema.org",
  "@type": "WebSite",
  "url": {{ site.BaseURL }}

Haven’t tested the code yet, but the surrounding quotes will be required by the structured data for this to be valid.

You can see it here ช่องค้นหาไซต์ลิงก์ | Google Search Central  |  เอกสารประกอบ  |  Google Developers

Is the engine rendering the quotes?

Please do.


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.