函数文档

wp_robots_sensitive_page()

💡 云策文档标注

概述

wp_robots_sensitive_page() 是一个 WordPress 函数,用于向 robots 元标签添加 noindex 和 noarchive 指令,以防止搜索引擎索引和存档敏感页面内容。

关键要点

  • 函数作为 wp_robots 过滤器的回调使用,通过 add_filter('wp_robots', 'wp_robots_sensitive_page') 调用。
  • 接收一个关联数组参数 $robots,表示当前的 robots 指令,并返回修改后的数组。
  • 在函数内部,将 $robots['noindex'] 和 $robots['noarchive'] 设置为 true,以启用相应指令。
  • 此函数从 WordPress 5.7.0 版本开始引入。

代码示例

function wp_robots_sensitive_page( array $robots ) {
    $robots['noindex']   = true;
    $robots['noarchive'] = true;
    return $robots;
}

📄 原文内容

Adds noindex and noarchive to the robots meta tag.

Description

This directive tells web robots not to index or archive the page content and is recommended to be used for sensitive pages.

Typical usage is as a ‘wp_robots’ callback:

add_filter( 'wp_robots', 'wp_robots_sensitive_page' );

Parameters

$robotsarrayrequired
Associative array of robots directives.

Return

array Filtered robots directives.

Source

function wp_robots_sensitive_page( array $robots ) {
	$robots['noindex']   = true;
	$robots['noarchive'] = true;
	return $robots;
}

Changelog

Version Description
5.7.0 Introduced.