From 48b6cf3719c7d008724236e2c13af866aa2bfab7 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Fri, 6 Sep 2024 01:26:09 +0200 Subject: [PATCH] Exclude internal URL from indexing --- includes/functions/_setup-wordpress.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/includes/functions/_setup-wordpress.php b/includes/functions/_setup-wordpress.php index 66e97029..51f87731 100644 --- a/includes/functions/_setup-wordpress.php +++ b/includes/functions/_setup-wordpress.php @@ -1577,3 +1577,25 @@ add_filter( 'get_the_excerpt', 'fictioneer_fix_excerpt', 10, 2 ); function fictioneer_replace_br_with_whitespace( $text ) { return str_replace( '
', ' ', $text ); } + +// ============================================================================= +// TRY PREVENTING INDEXING OF INTERNAL URLS +// ============================================================================= + +/** + * Add noindex and nofollow headers to certain requests + * + * @since 5.23.1 + */ + +function fictioneer_block_pages_from_indexing() { + $params = ['oauth_nonce', 'nonce', 'return_url', 'order', 'orderby', 'ago']; + + foreach ( $params as $param ) { + if ( isset( $_GET[ $param ] ) ) { + header( 'X-Robots-Tag: noindex, nofollow', true ); + break; + } + } +} +add_action( 'send_headers', 'fictioneer_block_pages_from_indexing' );