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.
By Scott Farrell on December 29th, 2015 , Follow @scott_WordPress Tweet to @scott_WordPressEmail or call, and we can arrange a time to chat call 0412927156 or CONTACT US TODAY!