CMS Hack: Dynamic Code | Header & Footer

I need a hack that allows me to add dynamic code to the header/footer of a CMS record.

I’m aware of this method:

<link href="https://www.example.com/SLUG FIELD" rel="canonical"/>

But I need to make the whole thing dynamic and render correctly (< instead of &lt;).

I read somewhere that this isn’t possible, but that’s why I’m looking for an “out of the box” solution.

I’m using schema JSON markup on a CMS collection. Some pages have a video, others don’t. I need to apply schema accordingly and there’s no way to do this by simply inserting a field into a header/footer tag. If I could filter, I would. Not possible.

Any information you can provide would be very much appreciated.


Here is my site Read-Only: LINK
(how to share your site Read-Only link)

Hi there, not sure what you mean by that. Is all you need the following? You can add things like this into the Custom Code section of the CMS Template page settings.

Thanks @spirelli. Yes, I am aware of this technique. I did my best to explain that in paragraph three but may have fallen short.

To answer your question, imagine I’m trying to make the whole code (highlighted in your example) dynamic. In my original post, I’m trying to add specific schema JSON to some and not others. I can’t just slot in the field between the quotation marks. I need to have specific tags on one page and not another.

Thank you for attempting to answer this.

1 Like

I have the same issue, did you find an answer?

Hello @Joachim_B. Yes, I made my own solution which you can find here (example): The Cross at the Center - Part 1 | Sermon | Derek Prince Ministries

Here’s the code that resolved my original post:

<script>
if (!$("#youtube-video-1").hasClass("w-condition-invisible")) { // If YouTube video has been added, include the following Schema ('!' from this line reverses logic)
  var schema = {
  "@context":"https://schema.org",
  "@graph": [
  {
    "@type": "VideoObject",
    "name": "The Cross at the Center (Part 2)",
    "description": "The cross distinguishes Christianity from all other religions. It is the source of all grace, the basis of Satan&#39;s defeat, the door to God&#39;s secret wisdom, the ultimate demonstration of God&#39;s love.",
      "thumbnailUrl": [
        "https://img.youtube.com/vi/uys0luOM87U/mqdefault.jpg",
        "https://img.youtube.com/vi/uys0luOM87U/0.jpg",
        "https://img.youtube.com/vi/uys0luOM87U/maxresdefault.jpg"
       ],
       "author": {
            "@type": "Person",
            "name": "Derek Prince"
       },
       "publisher": {
        "@type": "Organization",
        "name": "Derek Prince Ministries",
        "logo": {
        "@type": "ImageObject",
        "name": "Derek Prince Ministries",
        "url": "https://global-uploads.webflow.com/5f6175a45ad601c93a7b2a10/6010983d98361736dddd5b8c_logo_derek_prince_international_01_blue.svg",
        "width": 1200,
        "height": 257
        }
        },
       "uploadDate": "2015-04-17",
       "contentUrl": "https://www.youtube.com/watch?v=uys0luOM87U",
       "embedUrl": "https://www.youtube.com/embed/uys0luOM87U"
   }
     ]
  }    
      var script = document.createElement('script');
        script.type = "application/ld+json";
        script.text = JSON.stringify(schema);

        document.querySelector('body').appendChild(script);
        
}        
</script>

Thanks @Evan1 , I have solved my issue!

1 Like

Well done :clap:

Great to see some options.