0

my head looks like this: https://www.dropbox.com/s/7phmhirwzcrzvp3/head.php?dl=0 I want to add noindex,follow to certain pages and I have tried adding this

    <?php if($paged > 1 || is_archive || is_404 ||is_page(array( 2,4,6 ))){echo '<meta name="robots"content="noindex,follow" />'; } ?> 

but then ALL my pges except the homepage are set to noindex,follow...can someone tell me if I need to change the code or where exactly I would need to put it??

Makoto
  • 104,088
  • 27
  • 192
  • 230
  • `is_archive` probably will return always false because you didnt define th constant? or `$paged` != `$page` ... what is `is_page()`? Need more information, problem is not reproducable. – Daniel W. Sep 17 '15 at 15:51

1 Answers1

0

Obviously the variables and constants you use do not contain the stuff you expect them to.

Your best choice is to iterate your conditions until. Starting with…

<?php if($paged > 1){echo '<meta name="robots"content="noindex,follow" />'; } ?> 

…going to…

<?php if($paged > 1 || is_archive){echo '<meta name="robots"content="noindex,follow" />'; } ?> 

…and so on.

Oh, and have a look at your error log. is_archive looks like a constant, but you might mean is_archive() or $is_archive. Your error log might reveal such issues - even more so, if you set error_reporting(E_STRICT); to be especially picky about unset variables.

Another way would be var_dump(); for every variable you want to use in your condition, for you to check what content is in your variables. Like:

<?php var_dump(array($paged > 1,is_archive, is_404,is_page(array( 2,4,6 )))); ?> 
fboes
  • 2,149
  • 16
  • 17
  • fboes, if i add the var_dump, no page is getting noindex at all. I am not experienced in programming at all...would it be better to put this in a function somehow? – Madita von Birkenlund Sep 17 '15 at 16:36
  • The idea is, that `var_dump` tells you the content of your given variables. Just past the `var_dump`-line into your HTML, and you will see if your condition is met. Otherwise I strongly recommend turning on error reporting and observing errors in your error log. – fboes Sep 18 '15 at 13:47