Fix Delayed WordPress Embeds with the iframe Loading FilterFix Delayed WordPress Embeds with the iframe Loading Filter
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
If you embed a video or a map in a WordPress post, and the embed is not the very first thing in that post, it stays empty for a while. Readers reach it before it arrives.
WordPress adds a short delay instruction to the pictures and embedded frames inside a post. The instruction means: do not load me until the visitor scrolls close. For media deep in a post, that works well. The page loads fast, and the video is ready by the time a reader gets there.
WordPress makes one exception. The first picture or frame in a post does not get the delay, because it is assumed to be the first thing people see. That assumption holds for single-column posts, where the layout stacks one item after another.
It breaks when a post starts with two elements that compete for the top. An intro video above a main video. A header image above a product video. Then the second element is the one a visitor sees from the start, and the second element is the one carrying the delay. The reader looks at an empty box.
The change is a filter with one search line. It tells WordPress to load a certain embed right away instead of leaving it delayed.
add_filter( 'wp_iframe_tag_add_loading_attr', function( $value, $iframe, $context ) { if ( 'the_content' === $context ) { if ( false !== strpos( $iframe, 'youtube.com' ) ) { return 'eager'; } } return $value; }, 10, 3 );
Put the name of the platform you embed in the search line: vimeo.com, maps.google.com, spotify.com. Only embeds that match change. Everything else keeps the delay.
A quick way to see whether your site has the problem: open one of your posts in a private window, press F12, and watch the network list. A delayed embed starts fetching long after the page has finished drawing.
Post image
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started