give us a call

02 8011 4363

How to stop google indexing my staging site

If you’re not careful, google will index your staging site, causing reduced SEO, plus other issues. Here’s how to stop it. Put this code in your header.php in your theme, either before the <title> tag, or after the </tilte> tag.

<?php
if( strpos ($_SERVER[‘HTTP_HOST’] , ‘staging’) > -1 ) {
echo ‘<meta name=”robots” content=”noindex,nofollow”>’ ;
}
?>

So how does it work ? it looks for the word ‘staging’ in the server name, and displays the noindex rule for google. But when your site is pushed to production, and loses the staging in the server name, the noindex is also removed.

Comments are closed.