You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Yoast输出的Schema.org标记移至<head>底部?

解决Yoast Schema.org标记移至标签底部的方案
  • 第一步:用现有过滤器移除Yoast默认输出的Schema标记
    add_filter( 'wpseo_json_ld_output', '__return_false' );
    
  • 第二步:通过wp_head钩子设置低优先级(比如999),重新输出Schema内容,确保它出现在标签底部
    add_action( 'wp_head', 'custom_output_yoast_schema', 999 );
    function custom_output_yoast_schema() {
        if ( function_exists( 'WPSEO_JSON_LD' ) ) {
            $json_ld = new WPSEO_JSON_LD();
            $json_ld->output();
        }
    }
    

说明

  • 给wp_head钩子设置高数值优先级(999),能让这个函数在多数其他wp_head钩子函数之后执行,从而把Schema标记放在底部位置
  • 调用Yoast内置的WPSEO_JSON_LD类的output()方法,保证输出的Schema内容和原Yoast生成的完全一致

内容的提问来源于stack exchange,提问作者Wanderlust Consulting

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 23:52:32