Replace YouTube iframe with preview image


This feature detects the presence of compatible YouTube iframes in your site, and changes their markup so that the iframe tag is replaced by an img tag containing the thumbnail that's set by default on YouTube. Once a visitor clicks on the thumbnail, the iframe tag will be loaded and the video will be played.

You can select the resolution of the thumbnail by checking this guide.

If the LazyLoad for images feature is enabled, the thumbnail will be lazyloaded as well.

How to Check if Replace YouTube Iframe with Preview Image Feature is Working

Markup changes

WP Rocket will apply changes to the HTML markup. To look for them follow these steps:

  1. Open your browser and visit the page with the YouTube iframe present.
  2. Open the Developer tools.   

    - In Chrome: Chrome Menu in the upper-right-hand corner of the browser window → select More Tools > Developer Tools → Elements.  
    - In Firefox: Firefox Menu in the upper-right-hand corner of the browser window → Web Development → Inspector  
    - In Safari: Develop → Connect Web Inspector → Elements
  3. Click on the “Select an element in the page to inspect” icon and select the YouTube iframe.
  4. Identify the .rll-youtube-player class

    See below image for reference:

    youtube iframe lazyloadFull-size image URL

It’s possible to notice the changes applied by our feature (that won’t be present in the non-cached page). The changes are the following:

  • The rll-youtube-player class will be added to the iframe.
  • If the LazyLoad for images feature is enabled, the <img> tag for the preview image will have loading=”lazy", class=”lazyloaded” and data-ll-status=”loaded”.

Use the Network tab in your browser

Alternatively, you can confirm the feature is working by looking for YouTube’s files like embed.js, remote.js, endscreen.js, and others. Those should be loaded only after you click the “play” button. 

  1. Open your browser and visit the page with the YouTube iframe present.
  2. Open Developer tools.
  3. Click on the Network tab.
  4. Click on the JS filter.
  5. Click on the “play” button. YouTube's files should be loaded after that.

When our feature is disabled/not working, these files will be loaded immediately when the page loads.

See below how to check it’s working:

iframes lazyload scripts

If what you are seeing doesn’t look like the above illustrations, the feature isn’t working properly and you can contact our support team.

Compatible Markup

In order to apply the Replace YouTube iframe with preview image feature, WP Rocket is looking for iframe that contains src attribute with the YouTube URL.


<iframe class="tcb-responsive-video" data-code="g_v3gxJYM0Q" data-provider="youtube" src="" data-src="" frameborder="0" allowfullscreen=""></iframe>

Known issues

  • Sometimes, this feature can add an empty space below or above the iframe. For more information and suggested solutions, please check this article.
  • If you are using the Complianz plugin and have enabled YouTube blocking in the Services section, this will prevent the Replace YouTube iframe with preview image feature from working. It changes the HTML markup of the video so that it cannot be detected by WP Rocket. Disable this setting to remove the block:

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.