Elementor后端显示正常 前端未加载Bebas Neue字体求助
WordPress特定页面加载Bebas Neue字体异常问题求助
在WordPress站点的特定页面加载自定义字体Bebas Neue时出现异常:Elementor编辑器(后端)中字体显示正常,但预览或发布后前端却渲染为Poppins字体。开发者工具显示元素的font-family为"Bebas Neue", sans-serif;,但视觉呈现仍是Poppins,且控制台无CORS、404或混合内容类错误。
已尝试的排查步骤
- 检查Elementor字体设置:确认Elementor>Settings未禁用Google Fonts,通过Elementor>Tools重新生成CSS并清除缓存;
- 验证主题样式:检查主题
style.css及WordPress自定义器,未发现强制设置font-family: 'Poppins' !important;的规则; - 禁用缓存压缩工具:清除主机缓存、浏览器缓存,使用无痕模式访问,问题依旧;
- 尝试本地字体加载:将Bebas Neue的ttf文件上传至自定义主题
fonts/目录,在自定义CSS中添加@font-face规则并仅在目标页面加载,无效; - 通过
functions.php强制加载字体:分别尝试在线字体和本地字体的加载代码,均无效。
已使用的functions.php代码
在线字体加载实现
function cargar_bebas_en_pagina_especifica() { if ( is_page( 'lotes-y-terrenos-en-san-martin-de-los-andes' ) ) { wp_enqueue_style( 'bebas-neue-font', 'https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap', [], null ); wp_add_inline_style( 'bebas-neue-font', "body { font-family: 'Bebas Neue', sans-serif !important; }" ); } } add_action( 'wp_enqueue_scripts', 'cargar_bebas_en_pagina_especifica' );
本地字体加载实现
function cargar_fuente_local_bebas() { // Verifica si es la página con slug 'lotes-y-terrenos-en-san-martin-de-los-andes'. if ( is_page( 'lotes-y-terrenos-en-san-martin-de-los-andes' ) ) { // Encola el CSS local que contiene la declaración @font-face wp_enqueue_style( 'bebas-neue-local', get_stylesheet_directory_uri() . '/fonts/bebas-neue/bebas-neue.css', array(), null ); // Opcional: Forzar el uso de 'Bebas Neue' en body (y otros elementos) con !important // Esto ayudará a sobrescribir posibles estilos de tema/plugins $css_force = " body, h1, h2, h3, h4, h5, h6, p { font-family: 'Bebas Neue', sans-serif !important; } "; wp_add_inline_style( 'bebas-neue-local', $css_force ); } } add_action( 'wp_enqueue_scripts', 'cargar_fuente_local_bebas' );
所有组件均已更新至最新版本,恳请提供更多排查思路。
内容的提问来源于stack exchange,提问作者Jasper
相关产品推荐
相关产品推荐

