函数文档

wp_no_robots()

💡 云策文档标注

概述

wp_no_robots() 是一个已弃用的 WordPress 函数,用于输出 noindex meta 标签,以阻止搜索引擎索引页面内容。它通常作为 'wp_head' 钩子的回调函数使用。

关键要点

  • wp_no_robots() 在 WordPress 5.7.0 版本中被弃用,建议改用 wp_robots_no_robots() 函数,并通过 'wp_robots' 过滤器应用。
  • 该函数检查博客的公开设置(get_option('blog_public')),如果设置为公开,则输出 noindex 标签;否则不输出。
  • 典型用法:add_action('wp_head', 'wp_no_robots'); 作为 wp_head 钩子的回调。

注意事项

  • 由于已弃用,新开发中应避免使用 wp_no_robots(),转而使用 wp_robots_no_robots() 以保持兼容性和最佳实践。
  • 函数内部使用 _deprecated_function() 标记弃用状态,并在调用时触发相关通知。

📄 原文内容

Display a noindex meta tag.

Description

Outputs a noindex meta tag that tells web robots not to index the page content.

Typical usage is as a ‘wp_head’ callback:

add_action( 'wp_head', 'wp_no_robots' );

Source

function wp_no_robots() {
	_deprecated_function( __FUNCTION__, '5.7.0', 'wp_robots_no_robots()' );

	if ( get_option( 'blog_public' ) ) {
		echo "<meta name='robots' content='noindex,follow' />n";
		return;
	}

	echo "<meta name='robots' content='noindex,nofollow' />n";
}

Changelog

Version Description
5.7.0 Deprecated. Use wp_robots_no_robots() instead on 'wp_robots' filter.
5.3.0 Echo noindex,nofollow if search engine visibility is discouraged.
3.3.0 Introduced.