diff --git a/functions-addon.php b/functions-addon.php index 97e4d660..0cb0149d 100644 --- a/functions-addon.php +++ b/functions-addon.php @@ -26,6 +26,36 @@ spl_autoload_register(function ($class) { } }); +// ============================================================================= +// FONT PRELOAD - Previene CLS por font swap +// ============================================================================= + +/** + * Precarga fuentes críticas para prevenir CLS por font swap + * + * Las fuentes Poppins se precargan con alta prioridad para que estén + * disponibles cuando el CSS las necesite, evitando el "flash" de + * fuente de respaldo que causa layout shift. + */ +add_action('wp_head', function() { + $theme_url = get_template_directory_uri(); + + // Fuentes críticas: regular y 600 (usadas en títulos y body) + $critical_fonts = [ + 'poppins-v24-latin-regular.woff2', + 'poppins-v24-latin-600.woff2', + ]; + + foreach ($critical_fonts as $font) { + printf( + '%s', + esc_url($theme_url), + esc_attr($font), + "\n" + ); + } +}, 1); // Priority 1 = muy temprano en wp_head + // ============================================================================= // HELPER FUNCTION: roi_get_component_setting() - GENÉRICA // =============================================================================