Disabling Yoast Seo

自 Yoast SEO 14.0 起,我们已更改您与 Yoast SEO 输出交互的方式。 但在某些情况下,您可能希望禁用特定文章上的 Yoast SEO 输出。

请将以下代码添加到您主题的 functions.php 文件中。

add_action( 'template_redirect', 'remove_wpseo' );

/**
 * 在前端为特定文章、页面或自定义文章类型移除 Yoast SEO 的输出。
 */
function remove_wpseo() {
	if ( is_single ( 1 ) ) {
		$front_end = YoastSEO()->classes->get( Yoast\WP\SEO\Integrations\Front_End_Integration::class );

		remove_action( 'wpseo_head', [ $front_end, 'present_head' ], -9999 );
	}
}

以上示例将禁用 ID 为 1 的文章的输出。您也可以调整代码以适应多种不同情况:

if ( is_page ( 1 ) ) { //... }
if ( is_single( [ 123456, 234567, 345678 ] ) ) { //... }
if ( is_singular( 'my_custom_posttype' ) ) { //... }

版本号 #2
由 壳壳虫 创建于 2026-03-27 01:08:40 UTC
由 壳壳虫 更新于 2026-03-27 01:08:40 UTC