diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 783606df4b..7e0ecd64d3 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -238,6 +238,7 @@ add_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); // Robots filters. add_filter( 'wp_robots', 'wp_robots_noindex' ); +add_filter( 'wp_robots', 'wp_robots_noindex_embeds' ); add_filter( 'wp_robots', 'wp_robots_noindex_search' ); add_filter( 'wp_robots', 'wp_robots_max_image_preview_large' ); @@ -611,7 +612,6 @@ add_action( 'embed_footer', 'print_embed_sharing_dialog' ); add_action( 'embed_footer', 'print_embed_scripts' ); add_action( 'embed_footer', 'wp_print_footer_scripts', 20 ); -add_filter( 'wp_robots', 'wp_embed_no_robots' ); add_filter( 'excerpt_more', 'wp_embed_excerpt_more', 20 ); add_filter( 'the_excerpt_embed', 'wptexturize' ); add_filter( 'the_excerpt_embed', 'convert_chars' ); diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php index 5336b187f2..7c5ac83f24 100644 --- a/src/wp-includes/embed.php +++ b/src/wp-includes/embed.php @@ -1243,23 +1243,3 @@ function wp_filter_pre_oembed_result( $result, $url, $args ) { return $result; } - -/** - * Adds noindex to the robots meta tag for embeds. - * - * Typical usage is as a {@see 'wp_robots'} callback: - * - * add_filter( 'wp_robots', 'wp_embed_no_robots' ); - * - * @since 5.7.0 - * - * @param array $robots Associative array of robots directives. - * @return array Filtered robots directives. - */ -function wp_embed_no_robots( array $robots ) { - if ( ! is_embed() ) { - return $robots; - } - - return wp_robots_no_robots( $robots ); -} diff --git a/src/wp-includes/robots-template.php b/src/wp-includes/robots-template.php index 61931a25e5..19c7699790 100644 --- a/src/wp-includes/robots-template.php +++ b/src/wp-includes/robots-template.php @@ -74,6 +74,7 @@ function wp_robots() { * add_filter( 'wp_robots', 'wp_robots_noindex' ); * * @since 5.7.0 + * * @see wp_robots_no_robots() * * @param array $robots Associative array of robots directives. @@ -87,6 +88,28 @@ function wp_robots_noindex( array $robots ) { return $robots; } +/** + * Adds noindex to the robots meta tag for embeds. + * + * Typical usage is as a {@see 'wp_robots'} callback: + * + * add_filter( 'wp_robots', 'wp_robots_noindex_embeds' ); + * + * @since 5.7.0 + * + * @see wp_robots_no_robots() + * + * @param array $robots Associative array of robots directives. + * @return array Filtered robots directives. + */ +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 if a search is being performed. * @@ -99,6 +122,7 @@ function wp_robots_noindex( array $robots ) { * add_filter( 'wp_robots', 'wp_robots_noindex_search' ); * * @since 5.7.0 + * * @see wp_robots_no_robots() * * @param array $robots Associative array of robots directives.