A simple quick and easy solution to deploy a noindex tag on specific matching URLs or parameters using a PHP If conditional. This will be useful if you have limited to no access to amend the robots.txt or you're looking at building a conditional logic for keeping URLs out of Google's Index. Such as faceted URLs, empty product categories, seasonal URLs, etc.
Add the following PHP snippet to your global HEAD file (the file that controls the meta tags).
Before you add the PHP Conditional to noindex Matched URL, here are a few considerations. This method does not override any existing meta robots tags, it will add an additional tag if you have existing meta robots.
This method also assumes that you have a global (sitewide) file that controls metadata, for example, WordPress has the header.php file. You can add regex rules for faceted URLs, etc.
Add the following PHP snippet to your global HEAD file (the file that controls the meta tags).
Code:
<?php
$url = $_SERVER['REQUEST_URI'];
if (strpos($url,'/URI-GOES-HERE/') !== false) {
echo '<meta name="robots" content="noindex, nofollow" />' . "\n";
}
?>
Before you add the PHP Conditional to noindex Matched URL, here are a few considerations. This method does not override any existing meta robots tags, it will add an additional tag if you have existing meta robots.
This method also assumes that you have a global (sitewide) file that controls metadata, for example, WordPress has the header.php file. You can add regex rules for faceted URLs, etc.