Simple WordPress Trick #2 – Allow Only Testers To View Your Website

Today i’m sharing one simple trick for special situation – when your website is not ready yet and you don’t want visitors to access your website, but at the same time you want to share your website to some alpha testers or friends.
With special plugins may be you can solve this, but the simple code i give below solves this problem perfectly.
Just put this code to the 1st line of your theme’s header.php. You can edit html part of code’s echo part and put there any image, message for visitors which tells them your website is coming soon or under construction.

//put this code to the top of theme's header.php
session_start();
if (!isset($_GET["some_secret_key"]) and !isset($_SESSION["some_secret_key"])){

//edit this html in echo
echo '
<html>
<head><title>'.get_bloginfo('name').'</title></head>
<body bgcolor="#ffffff">
<center><img src="any_under_consctruction_or_maintenance_image_url_here"></center>
</body>
</html>';
die();
} else {$_SESSION["some_secret_key"]=1;}

// rest header.php codes here...

It is done. Now all visitors trying open your website will see under construction message, but with yourwebsite.com/?some_secret_key=1 url will open your website normally. So you can share this last link with your alpha testers.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.