0

I use Woocomerce for my WordPress site. For the print version of some sites I use a parameter like this http://www.mywebsite.de/kategorie/?wpp_export=print

How can i set these urls to noindex. I tried a code like this in the header.php:

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

But the code did not work. There is no noindex in the head of these sites…

Could you help me with this?

Best regards

Tom

Marc
  • 4,661
  • 3
  • 40
  • 62
tom84
  • 371
  • 1
  • 3
  • 15
  • `if ( isset( $_GET['wpp_export'] ) )` should do it and should be more reliable. If it doesn't work you should check if you edited the correct file (in the correct theme directory) and if you may see cached results. – Gerald Schneider Apr 25 '16 at 13:22

1 Answers1

0

The first thing that you should do is to register your GET variable wpp_export within your functions.php file:

add_action('init','add_get_val');
function add_get_val() { 
    global $wp; 
    $wp->add_query_var('wpp_export'); 
}

Then I would try using something like this to your header.php:

<?php

if ( get_query_var('wpp_export') ) {

     echo '<meta name="robots" content="noindex, follow" />';

}

?>

You can test the value of your GET variable like this:

<?php

if ( get_query_var('wpp_export') == 'print' ) {

     echo '<meta name="robots" content="noindex, follow" />';

}

?>
Marc
  • 4,661
  • 3
  • 40
  • 62