如何将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
相关产品推荐
相关产品推荐

