/** * Force `font-display:swap` for all @font‑face rules * — No Elementor Pro required. */ add_filter( 'style_loader_tag', function ( $html, $handle ) { // Skip if the CSS block isn't a font stylesheet if ( strpos( $html, '.woff' ) === false && strpos( $html, '.woff2' ) === false ) { return $html; } // Already has font-display set? leave it. if ( strpos( $html, 'font-display:' ) !== false ) { return $html; } // Inject CSS rule via preload hack $search = ''; $inject = '@font-face{font-display:swap;}'; $html = str_replace( $search, $inject . $search, $html ); return $html; }, 10, 2 ); /** * Elementor‑specific helper — tell Elementor to use `swap` * for every Custom Font it prints. * (Works in both free & Pro versions.) */ add_filter( 'elementor/fonts/font_display', function () { return 'swap'; // possible: auto | block | swap | fallback | optional } );