set urls with parameter to noindex in wordpress?

I’m looking for a solution to set all URLs which uses the parameter ‘?’ to noindex. I look for a php solution which I could use in the header.php in WordPress or in the .htaccess.

I tryed this:

Read More
<?php
$url = $_SERVER['REQUEST_URI'];
if( preg_match('/?/', $url) ) {
    echo '<meta name="robots" content="noindex, follow" />' . "n";
}
?>

This solution did not work and URLs with the parameter ‘?’ didn’t get a noindex attribute.

Best regards

Related posts

1 comment

  1. You can use strpos() function for that:

    <?php
        $url = $_SERVER['REQUEST_URI'];
        if (strpos($url,'?') !== false) {
            echo '<meta name="robots" content="noindex, follow" />' . "n";
        }
    ?>  
    

Comments are closed.