From 938d27abf2362bb77f731c4ccd13a52c31a36674 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Sun, 5 Jan 2025 22:12:25 +0000 Subject: [PATCH] Comments: Noindex pages containing unapproved comments. Adds a `noindex` directive to pages displaying a preview of an unapproved comment, ie pages with both an `approved` and `moderation-hash` parameter. This is to prevent the pages from appearing in search engines which can be the case if they ignore the canonical URL directive. Props peterwilsoncc, flixos90, joostdevalk. Fixes #62760. git-svn-id: https://develop.svn.wordpress.org/trunk@59576 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/default-filters.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 9eff6ecbeb..575e8a9175 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -366,7 +366,13 @@ add_action( 'after_switch_theme', '_wp_sidebars_changed' ); add_action( 'wp_enqueue_scripts', 'wp_enqueue_emoji_styles' ); add_action( 'wp_print_styles', 'print_emoji_styles' ); // Retained for backwards-compatibility. Unhooked by wp_enqueue_emoji_styles(). -if ( isset( $_GET['replytocom'] ) ) { +if ( + // Comment reply link. + isset( $_GET['replytocom'] ) + || + // Unapproved comment preview. + ( isset( $_GET['unapproved'] ) && isset( $_GET['moderation-hash'] ) ) +) { add_filter( 'wp_robots', 'wp_robots_no_robots' ); }