Reputation: 409
I have to add noindex to some url's, this is my code at the moment:
<?php if ($metanoindex) { ?>
<meta name="robots" content="noindex,follow" />
<?php } elseif ($_SERVER['REQUEST_URI']=='/dolls/1/bestselling' ) { ?>
<meta name="robots" content="noindex,follow" />
<?php } elseif ($_SERVER['REQUEST_URI']=='/dolls/1/bestselling/30' ) { ?>
<meta name="robots" content="noindex,follow" />
<?php } elseif ($_SERVER['REQUEST_URI']=='/dolls/1' ) { ?>
<meta name="robots" content="noindex,follow" />
<?php } else { ?>
<meta name="robots" content="index,follow" />
<?php } ?>
I wondered if there is a way to make an array of urls instead of repeating "else if" each time.
Upvotes: 1
Views: 174
Reputation: 15981
Try as below
<?php
$arr = array('/dolls/1/bestselling','/dolls/1/bestselling/30','/dolls/1');
if($metanoindex || in_array($_SERVER['REQUEST_URI'],$arr)){ ?>
<meta name="robots" content="noindex,follow" />
<?php
}
else {
?>
<meta name="robots" content="index,follow" />
<?php } ?>
PHP Manual: in_array()
Upvotes: 2
Reputation: 5127
$urls = array('/dolls/1/bestselling', '/dolls/1/bestselling/30', '/dolls/1');
if (in_array($_SERVER['REQUEST_URI'], $urls)) {
// Insert meta tag here
}
Upvotes: 1