Skip to content

Commit

Permalink
Comments: Noindex pages containing unapproved comments.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
peterwilsoncc committed Jan 5, 2025
1 parent bb3f90f commit 938d27a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,13 @@
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' );
}

Expand Down

0 comments on commit 938d27a

Please sign in to comment.