函数文档

wp_robots_noindex_embeds()

💡 云策文档标注

概述

wp_robots_noindex_embeds() 是一个 WordPress 函数,用于在嵌入页面时向 robots 元标签添加 noindex 指令,以防止搜索引擎索引这些页面。

关键要点

  • 函数作为 wp_robots 过滤器的回调使用,通过 add_filter('wp_robots', 'wp_robots_noindex_embeds') 调用。
  • 当 is_embed() 返回 true 时,函数调用 wp_robots_no_robots() 来添加 noindex 指令。
  • 参数 $robots 是一个关联数组,表示 robots 指令,函数返回过滤后的数组。
  • 该函数从 WordPress 5.7.0 版本开始引入。

代码示例

function wp_robots_noindex_embeds( array $robots ) {
	if ( is_embed() ) {
		return wp_robots_no_robots( $robots );
	}

	return $robots;
}

📄 原文内容

Adds noindex to the robots meta tag for embeds.

Description

Typical usage is as a ‘wp_robots’ callback:

add_filter( 'wp_robots', 'wp_robots_noindex_embeds' );

See also

Parameters

$robotsarrayrequired
Associative array of robots directives.

Return

array Filtered robots directives.

Source

function wp_robots_noindex_embeds( array $robots ) {
	if ( is_embed() ) {
		return wp_robots_no_robots( $robots );
	}

	return $robots;
}

Changelog

Version Description
5.7.0 Introduced.