1

i need help about adding x-robots-tag to certain url pattern.

My web site have many ?nonamp=1 ?amp kind of pattern that getting crawled by search engines. I would like to let engines crawl those urls but not want them to index these ones. (i couldn't add php no-index header for these certain url patterns)

My question is how can i add x-robots-tag to those urls pattern on my web server.

Web server: openlitespeed
Site: php (Wordpress)

Sample URLS:

example.com/amazon-nedir-amazonda-satis-nasil-yapilir/?amp=1

/amazon-nedir-amazonda-satis-nasil-yapilir/?nonamp=1

/amazon-nedir-amazonda-satis-nasil-yapilir/?amp

I would like to add x-robots-tag to all these 3 end pattern (?amp=1, ?nonamp=1, ?amp)

Thanks for help. Best Regards.

Salahuddin Ahmed
  • 4,854
  • 4
  • 14
  • 35
damonbl
  • 13
  • 3

1 Answers1

1

In functions.php add those lines of code:

function add_header_xrobots($headers) {
    if (isset($_GET['amp']) || isset($_GET['noamp'])){
        $headers['X-Robots-Tag'] = 'noindex';
    }
    return $headers;     
}
add_filter('wp_headers', 'add_header_xrobots');

Edit noindex to right header content.

Nikita TSB
  • 440
  • 4
  • 11