Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Created August 15, 2018 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finalwebsites/e183ef28c1cb9b232330e75ff004d848 to your computer and use it in GitHub Desktop.
Save finalwebsites/e183ef28c1cb9b232330e75ff004d848 to your computer and use it in GitHub Desktop.
Add noindex to your WordPress website using the X-Robots-Tag header
<?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');
@finalwebsites
Copy link
Author

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:

User-agent: *
Disallow: */feed/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment