Created
August 15, 2018 06:04
-
-
Save finalwebsites/e183ef28c1cb9b232330e75ff004d848 to your computer and use it in GitHub Desktop.
Add noindex to your WordPress website using the X-Robots-Tag header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add this code to your theme's functions.php file | |
function add_noindex_for_feeds($headers) { | |
$req_uri = filter_input(INPUT_SERVER, 'REQUEST_URI'); | |
if ( '/feed/' == substr($req_uri, -6) ) { | |
$headers['X-Robots-Tag'] = 'noindex'; | |
} | |
return $headers; | |
} | |
add_filter('wp_headers', 'add_noindex_for_feeds'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Strange, the is_feed() conditional tag isn't working here...
Anyway I'm using this function now because the Google bot ignores these robots.txt rule on many sites I manage: