Speed & performance · Guide
How to Lazy Load YouTube Embeds in WordPress
Short answer
To lazy load YouTube embeds in WordPress, rely on core first: WordPress 5.7 adds loading=lazy to iframes with width and height. For embeds core misses, paste the iframe code into a Custom HTML block and add loading=lazy yourself. For pages with several videos, use a facade such as lite-youtube-embed, which shows a thumbnail until someone clicks.
Key takeaways
- A YouTube embed loads the full player on page open, and lazy-loading it saves around 500 KB on the first load.
- WordPress 5.7 adds loading=lazy to iframes with both width and height attributes.
- WordPress 5.9 skips the first content image or iframe from lazy loading, so top videos load at once.
- A facade shows a thumbnail and loads the real player only when someone clicks.
- Never lazy-load the video at the top of the page, and never drop the width and height attributes.
Why do YouTube embeds slow down a WordPress page?
A YouTube embed loads the full video player on page open, even when nobody presses play.
The embed is an iframe that pulls in the player, scripts and tracking from YouTube. Web.dev's iframe lazy-loading article says lazy-loading YouTube embeds saves around 500 KB on the first page load.
Each embed loads its own player, so the cost grows with every video on the page. A post with three videos pays the player cost three times before anyone watches anything.
The player also runs JavaScript on the main thread, which can delay interaction. Web.dev notes that Chrome.com cut time to interactive by 10 seconds by lazy-loading offscreen YouTube embeds.
What does lazy loading a YouTube embed do?
Lazy loading tells the browser to wait until the video is near the screen before it loads the player.
The browser-level loading attribute does this. Web.dev's iframe article explains that loading="lazy" defers offscreen iframes until the user scrolls near them.
A facade goes further. It shows a thumbnail and a play button, and loads the real player only when someone clicks.
Neither method changes the video itself. The same video plays when clicked, and only the timing of the download changes.
What do you need before you start?
You need an editor login, a list of the pages with YouTube embeds, and a speed reading from before the change.
- An editor or admin login for the site.
- A list of posts and pages with YouTube embeds. Search the site for
youtube.comto find them. - A before reading of the page weight or Largest Contentful Paint, so you can compare after the change.
- A backup if you plan to edit theme code for a facade.
Allow 15 to 30 minutes for the first page, and less for each page after that.
Does WordPress already lazy-load YouTube embeds?
Yes, since WordPress 5.7, for embeds that carry both width and height attributes.
WordPress 5.7 adds loading="lazy" to iframes in post content, excerpts and text widgets, using the browser-level loading attribute, according to the Make WordPress Core dev note. It only adds the attribute when the iframe has both width and height, to avoid layout shift.
Most YouTube embeds come from oEmbed. Pasting a YouTube URL into the editor turns it into embedded media, and the dev note says the loading attribute is added only when the provider's iframe markup includes both dimensions.
Check your own page source to see whether core already handled it. If the iframe shows loading="lazy", the browser will defer it, and you may not need to do anything.
WordPress 5.9 skips the first content image or iframe from lazy loading, according to the Make WordPress Core lazy-loading tag page. A video at the top of a post loads at once, which is the right call for the first thing visitors see.
That first video can be the Largest Contentful Paint element. Our guide to what Core Web Vitals are explains the metric in plain terms.
How do you lazy-load an embed with a Custom HTML block?
Paste the YouTube iframe code into a Custom HTML block and add loading="lazy" to the iframe tag.
- On YouTube, click Share, then Embed, and copy the iframe code.
- In the WordPress editor, add a Custom HTML block and paste the code.
- Add
loading="lazy"to the iframe tag, and keep the width and height attributes. - Give the iframe a
titleattribute that names the video, so screen readers can announce it.
The finished tag carries the embed address, a title that names the video, loading set to lazy, width 560, height 315, and the allowfullscreen attribute.
Replace VIDEO_ID with the code from the video's address. The width and height values of 560 by 315 come from YouTube's own embed code, as shown in the Web.dev example.
Use this method for one-off embeds. For many videos across the site, a plugin or a facade saves more work.
How do you use a facade instead?
A facade shows a thumbnail with a play button and loads the real player only when someone clicks.
The lite-youtube-embed web component by Paul Irish works this way. It renders a thumbnail and a play button, then swaps in the real iframe on click, and it uses the youtube-nocookie.com domain by default.
| Method | What loads before play | Effort | Best for |
|---|---|---|---|
| WordPress core lazy loading | Player, when the video nears the screen | None | Single embeds in posts |
loading="lazy" in Custom HTML | Player, when the video nears the screen | Low | One-off embeds |
| Facade (lite-youtube-embed) | Thumbnail and a small script only | Medium | Pages with several videos |
WordPress plugins offer the same idea without code. Search the plugin directory for a facade or lite embed plugin, and check that it is updated for your WordPress version.
A facade does not have every feature of the real embed, and autoplay can behave differently when the player loads late. Test the play button, the fullscreen button and the video title before you roll it out.
Should you use youtube-nocookie?
Yes, when privacy matters, since the youtube-nocookie.com address is YouTube's privacy-enhanced embed domain.
YouTube Help says privacy-enhanced mode stops views of the embedded video from shaping the viewer's later YouTube recommendations.
Swap www.youtube.com for www.youtube-nocookie.com in the embed address. The player still works, and the facade component above uses that domain by default.
It does not make the embed faster by itself. Use it for privacy, and use lazy loading or a facade for speed.
Can you lazy-load embeds from other video sites?
Yes, since the same loading attribute works for any iframe embed, including Vimeo.
Web.dev's iframe article notes that lazy-loading Instagram embeds can save about 100 KB on initial load, and the same approach works for Vimeo, maps and social posts.
Check each provider's embed code for width and height, since WordPress only adds the attribute when both are present. For providers that leave them out, paste the code into a Custom HTML block and add the attribute yourself.
What about self-hosted video?
For video files on your own site, add loading="lazy" and preload="none", and set a poster image.
Web.dev's lazy-loading video article says loading="lazy" prevents the poster image from loading until the video is near the viewport, and preload="none" stops the browser preloading any video data at all.
Self-hosted video still uses your server's bandwidth, so keep files small and consider a video host for long clips.
Videos can be the Largest Contentful Paint element. Web.dev notes that a poster image loads quicker than the video, so use a poster and do not lazy-load a video that is the first thing visitors see.
How do you check that it worked?
Open the page source and look for loading="lazy" on the iframe, then re-run the speed test.
In the browser, right-click the page and choose View Page Source, then search for “youtube” and check the iframe tag. If it shows loading="lazy", the browser will defer it. For a facade, the page source shows a thumbnail element instead of an iframe until you click.
Re-run the speed test and compare the before reading. Web.dev's figures say lazy-loading YouTube embeds saves around 500 KB on the first load, so the page weight should drop by roughly that much per embed.
Check Largest Contentful Paint and total blocking time in the same report. Our guide on how to pass Core Web Vitals in WordPress explains how to read those numbers.
Run the test in PageSpeed Insights or GTmetrix. Our comparison of the two tools explains what each one shows.
If the lab score barely moves, check field data too. Our guide to lab data vs field data explains why the two can disagree.
For the rest of the page, our guide to speeding up WordPress covers the other layers that sit around the video fix.
What mistakes should you avoid?
The main mistakes are lazy-loading the video at the top of the page, dropping the width and height, and forgetting the title attribute.
- Do not lazy-load the video at the top of the page. It is on screen at once, so waiting gains nothing.
- Do not remove width and height. WordPress only adds
loading="lazy"to iframes with both attributes, and missing dimensions cause layout shift. - Do not forget the
titleattribute. Screen readers announce the iframe, so name the video. - Do not use a facade for the main video on a video landing page. The extra click stands between the visitor and the reason they came.
- Do not assume one fix covers every embed. Check each page, since builders and widgets can output their own iframe code.
Frequently asked questions
Does WordPress lazy-load YouTube embeds on its own?
Yes, since WordPress 5.7, for iframes in post content, excerpts and text widgets that carry both width and height attributes. Check your page source for loading=lazy on the iframe. If it is missing, add the attribute yourself in a Custom HTML block.
What is the difference between lazy loading and a facade?
A facade shows a thumbnail with a play button and loads the real YouTube player only when someone clicks. Lazy loading still loads the player when the video nears the screen, while a facade loads nothing until the click, so it saves more on pages with several videos.
Will lazy loading hurt my YouTube views?
No. Lazy loading only changes when the player downloads, not the video itself. The same video plays when the visitor presses play, and the video page on YouTube is not affected at all.
Is there a more private way to embed a YouTube video?
Yes. Switch the embed to YouTube's privacy-enhanced mode, which stops the view from shaping the viewer's later recommendations. Facade tools load that privacy-enhanced player only after the visitor clicks play.
Why is my embed still loading at once?
The usual causes are a missing width or height on the iframe, which stops WordPress adding the attribute, or a builder widget that outputs its own iframe code. Check the page source for loading=lazy, and add the attribute in a Custom HTML block if the builder's output lacks it.
Sources
- It's time to lazy-load offscreen iframes! web.dev
- Lazy loading video web.dev
- Lazy-loading iframes in 5.7 Make WordPress Core
- Lazy-loading images and iframes Make WordPress Core
- lite-youtube-embed GitHub
- wp_lazy_loading_enabled() – Function WordPress Developer Resources
- Embed videos & playlists YouTube Help
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
