# Adding video to the header of the New CMS Article insted of the image

**URL:** <https://forum.bootstrapstudio.io/t/adding-video-to-the-header-of-the-new-cms-article-insted-of-the-image/12844>\
**Category:** Tips and Tricks\
**Created:** [November 22, 2026, 10:36am UTC](https://forum.bootstrapstudio.io/t/adding-video-to-the-header-of-the-new-cms-article-insted-of-the-image/12844 "2026-11-22T10:36:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SkyDrifter](https://forum.bootstrapstudio.io/user_avatar/forum.bootstrapstudio.io/skydrifter/32/5816_2.png) [@SkyDrifter](https://forum.bootstrapstudio.io/u/SkyDrifter)\
**Post date:** [November 22, 2026, 10:36am UTC](https://forum.bootstrapstudio.io/t/adding-video-to-the-header-of-the-new-cms-article-insted-of-the-image/12844/1 "2026-11-22T10:36:27Z")

</div>

Under the CMS Articles settings add a URL to custom fields.

 ![Screenshot 2026-11-23 021349](https://forum.bootstrapstudio.io/uploads/default/original/2X/9/9f0ed3ddc504c4a6e34fc9557365063ec03f11e5.png)

On top of your article.html page hide the image header, then add a Paragraph with ID of **cms-video-vault** and class **visually-hidden** under the CMS Loop,

 ![Screenshot 2026-11-22 052402](https://forum.bootstrapstudio.io/uploads/default/original/2X/d/d349b953925523796692f8d8366c39ab6aa0cc0b.png)

then link to the CMS URL you created,

 ![Screenshot 2026-11-22 053043](https://forum.bootstrapstudio.io/uploads/default/original/2X/d/d8843e3d2b5903feab71e6e3b6277b6348231b1e.png)

then add A Custom Code below the Paragraph with its ID like so.

```auto
<!-- The outer container defaults to display: none; and uses id="cms-video-container" so the script can control it -->
<div class="vsd">
<div id="cms-video-container" style="width: 100%; max-width: 92%; margin: 0 auto; display: none; border-radius: 12px; overflow: hidden; filter: drop-shadow(3px 1px 2px #3b3b3b);">
  <div class="ratio ratio-16x9" style="--bs-aspect-ratio: 100%; min-height: 350px; max-height: 985px; overflow: hidden;">
    <iframe id="cms-dynamic-player" src="" frameborder="0" 
            style="width: 100%; height: 100%;" 
            allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" 
            referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
  </div>
</div>
</div>

```

for clean look add style to brake the video from below content.

```auto
.vsd {
  margin-bottom: 30px;
}

```

then create .js file with code like so

```auto
// Insert the video in the header header
  (function() {
    var checkLimit = 0;
    
    function injectCmsAssets() {
      // 1. HANDLE THE YOUTUBE PLAYER AND VISIBILITY
      var vault = document.getElementById("cms-video-vault");
      var player = document.getElementById("cms-dynamic-player");
      var container = document.getElementById("cms-video-container");
      
      if (vault && player && container) {
        var rawUrl = (vault.textContent || vault.innerText || "").trim();
        
        if (rawUrl) {
          var targetEmbed = rawUrl;
          if (rawUrl.includes("watch?v=")) {
            var videoId = rawUrl.split("v=").split("&");
            targetEmbed = "https://youtube.com" + videoId;
          }
          
          if (player.src !== targetEmbed) {
            player.src = targetEmbed;
          }
          
          // REVEAL SWITCH: Reads the vault text, and updates the container layout display to block
          if (container.style.display !== "block") {
            container.style.display = "block";
          }
          
          clearInterval(assetEngineClock);
        }
      }

      // 2. DESTRUCTIVE RAW TEXT OVERRIDE FOR IMAGE D-BLOCK
      var articleWrapper = document.querySelector(".cms-article-wrapper");
      if (articleWrapper) {
        var figures = articleWrapper.querySelectorAll("figure");
        figures.forEach(function(fig) {
          if (fig.className.indexOf("d-block") !== -1) {
            fig.className = "figure d-flex justify-content-center align-items-center w-100";
            fig.style.setProperty("display", "flex", "important");
            fig.style.margin = "1.5rem 0";
          }
        });

        var images = articleWrapper.querySelectorAll("figure img");
        images.forEach(function(img) {
          img.style.setProperty("width", "100%", "important");
          img.style.setProperty("max-width", "650px", "important");
          img.style.setProperty("height", "auto", "important");
          img.style.borderRadius = "12px";
        });
      }
      
      if (checkLimit > 100) {
        clearInterval(assetEngineClock);
      }
      checkLimit++;
    }

    var assetEngineClock = setInterval(injectCmsAssets, 40);
  })();

```

on each article you want video header just put the embed YouTube’s URL in your created URL section.

 ![Screenshot 2026-11-23 021522](https://forum.bootstrapstudio.io/uploads/default/original/2X/8/8b3ce549ab6537b0450bf78ae75fb82b85e3f19f.png)

Results will be.

 ![Screenshot 2026-11-22 053232](https://forum.bootstrapstudio.io/uploads/default/original/2X/3/352cd388beb755f6f3bad7ed8b9e25413d36364a.jpeg)

if you need a header image for your articles after making the video header replacement,then in article’s content section at top be for you write article just add this snippet exactly so: **[img:/assets/img/yourimg.png]** ,

 ![Screenshot 2026-11-23 022208](https://forum.bootstrapstudio.io/uploads/default/original/2X/0/020be728742e8b027aa02446d25a84ed8b226529.png)

this is were the next .js code will inject the image in to the article.Next on the article.html page add another Custom Code below the first one with this,note the ID as the js code need this.

```auto
<img id="img-head" src="your-image.jpg" style="display: block; margin: 0 auto;width: 90%;max-height: 860px; border-radius: 12px; margin-bottom:18px; box-shadow: 3px 1px 2px #3b3b3b;">

```

then add the the this code to the .js file.

```auto
// 2. replace top image for articles
document.addEventListener('DOMContentLoaded', function() {
    console.log('Root directory image path correction active');

    var tagStart = '[img:';
    var walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
    var targetNode = null;
    var targetImage = document.getElementById('img-head');

    // 1. Locate the exact text node containing your [img:...] tag
    while (walker.nextNode()) {
        if (walker.currentNode.nodeValue.indexOf(tagStart) !== -1) {
            targetNode = walker.currentNode;
            break;
        }
    }

    var imageInjected = false;

    if (targetNode) {
        var textValue = targetNode.nodeValue;
        var startIndex = textValue.indexOf(tagStart);
        var endIndex = textValue.indexOf(']', startIndex);

        if (startIndex !== -1 && endIndex !== -1) {
            // 2. Isolate your exact path: 'game-bg/RSI/IAE.webp'
            var cleanImagePath = textValue.substring(startIndex + tagStart.length, endIndex).trim();

            if (cleanImagePath && targetImage) {
                // Force root-relative path if missing leading '/' or 'http'
                if (cleanImagePath.indexOf('/') !== 0 && cleanImagePath.indexOf('http') !== 0) {
                    cleanImagePath = '/' + cleanImagePath;
                }

                // Append the timestamp query parameter for local caching protection
                var freshUrl = cleanImagePath + '?t=' + new Date().getTime();

                // Hide the image automatically if the file fails to load (404/broken path)
                targetImage.onerror = function() {
                    targetImage.style.display = 'none';
                    console.log('Error: Image failed to load, hiding #img-head:', freshUrl);
                };

                targetImage.src = freshUrl;
                targetImage.setAttribute('src', freshUrl);
                targetImage.style.display = 'block';
                imageInjected = true;
                console.log('Successfully injected root path address:', freshUrl);
            } else if (!targetImage) {
                console.log('Error: Element with id="img-head" was not found on the page.');
            }

            // 4. HIDE TAG COMPLETELY: Wipe the raw text out of the screen view safely
            var fullTagText = textValue.substring(startIndex, endIndex + 1);
            targetNode.nodeValue = textValue.replace(fullTagText, '');
        }
    }

    // 5. HIDE IMAGE ELEMENT: If no valid [img:...] tag was found, hide #img-head
    if (!imageInjected && targetImage) {
        targetImage.style.display = 'none';
        console.log('No [img:...] tag found, hiding #img-head.');
    }
});

```

 ![Screenshot 2026-11-22 052817](https://forum.bootstrapstudio.io/uploads/default/original/2X/b/b2721ce52b41ef60a6ea1ccc651366900b97247e.jpeg)
