search ]

Add loading=”lazy” to iframes

WordPress adds loading="lazy" to images by default, but not to iframes (YouTube, maps, etc.). The following code adds lazy loading to iframes. For more performance tips, see the Guide to Google PageSpeed for WordPress.

add_filter( 'the_content', function( $content ) {
	return preg_replace( '/<iframe/', '<iframe loading="lazy"', $content );
} );
Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo