There are a many ways to develop a website in WordPress, locally, on a sub-domain or on a staging server but these ways mean that you will eventually have to migrate the site to a the live url at some point and sync the database. Although very achievable it can be a pain in the proverbial, especially if you are using some plugins that don’t store data in the database. Yes, you can use a plugin to make a website non public and develop that way but there’s more than one way to skin a cat!
This method will allow you to create a holding page, create a user as a subscriber and give them access to the site as it would be seen on a public url without giving them access to the dashboard.
So first off you will need WordPress installed on the server and on the url you intend the site to go live on. You will also need a simple holding page build with simple html like so:
[code]
<!DOCTYPE HTML>
<html>
<head>
<title>New Website coming soon!</title>
</head>
<body>
<h1>Congratulations you’ve just redirected non logged in users to this holding page.</h1>
</body>
</html>
[/code]
Save that file in your theme folder and call it ‘holdingpage.php’
Now you need to redirect any users coming to the site to this page. You can simply do that by either putting this code in your index.php, home.php file or a template file that you might be using as the front page for your wordpress site. With the following I’ve used a custom template that is being used as the front page set in the WordPress dashboard under Settings > Reading.
[code]
<?php
/* Template Name: Custom Page */
if ( !is_user_logged_in()) {
get_template_part(‘holdingpage’);
exit(0);
}
get_header(); ?>
[/code]
*** UPDATED ***
Rather than redircting on an individual template it might be better to create an overall function filter that will apply to all of your theme files including page.php, single.php, archive.php etc etc. the way to do that is to add a filter hook to the wp_headers function, add this to your themes function.php file:
[code]
function sthn_header_redirect() {
if ( !is_user_logged_in()) {
get_template_part(‘holdingpage’);
exit(0);
}
}
add_filter(‘wp_headers’, ‘sthn_header_redirect’);
[/code]
*** UPDATED ***
This will redirect any non logged in users to the page called holdingpage.php in the theme folder. Now you can start to develop your WordPress site without worrying your client is going to look unprofessional with an under developed site, and they will be happy because they’ve got a nice neat holding page. To stop spiders crawling the site just put a disallow on the root in a robot.txt file in the main directory of your website.
After sometime you will have your site well under development and perhaps you’ll want to show the client some progress. No problem, what you’ll need to do is set them up as a user for the site specifically as a subscriber but first you need to paste this in to your functions.php file:
[code]
//redirect subscribers to the home url
add_action( ‘admin_init’, ‘custom_profile_redirect’, 12 );
function custom_profile_redirect() {
global $current_user;
get_currentuserinfo();
if ($current_user->user_level == 0)
{
wp_redirect( home_url() ); exit;
}
}
[/code]
This will redirect subscribers to the home url and because they are logged in not only will they bypass the dashboard they will also bypass the holding page conditional and load the theme as it would normally on a live site.
The next bit of code is optional but, by putting it in the function.php file it will hide the admin bar from the user – handy if you just want the user to see the site as it would look live.
[code]
// hide adminbar
if (!current_user_can(‘administrator’)) :
show_admin_bar(false);
endif;
[/code]
Once the user (subscriber) has logged in they will need to logout or they might never see their lovely holding page again! Now we wouldn’t want to cause any unnecessary panic would we! So, it’s worth putting a logout url and you can do that by dropping this in to your header or footer somewhere:
[code]
<?php echo wp_logout_url( home_url() ); ?>
[/code]
There are other applications for this and this is just a simple “Developing a WordPress site on a live url” technique that you can use for your clients, any other ways would be useful to hear about so feel free to leave a comment.
Hi Elliott, I have to say I’ve never seen this method used before.
I would normally just build a normal holding page, and build WordPress in a new Directory then move out the index.php, and wp-config. Does this method have any benefits? I know it “could” be found but my directory normally has a random name that couldn’t be guessed.
I appreciate your opinion, it certainly seems a far more professional way to do things.
Lorraine.
Thanks for the feedback Lorraine.
Although your directory is not public – spiders could technically still crawl and index your pages in Google without a block on that directory. The benefit of doing it this way for me is to cut out the hassle of re-syncing the database and correcting the permalinks no other reason really 🙂 – for live sites that are already running on a url I still have to develop in a similar way to you and have the agro of the re-syncing.
This is just an attractive alternative that uses the wp core to login also, users can get familiar with the wp login process 😉
Hi Elliott, I have to say I’ve never seen this method used before.
I would normally just build a normal holding page, and build WordPress in a new Directory then move out the index.php, and wp-config. Does this method have any benefits? I know it “could” be found but my directory normally has a random name that couldn’t be guessed.
I appreciate your opinion, it certainly seems a far more professional way to do things.
Lorraine.
Thanks for the feedback Lorraine.
Although your directory is not public – spiders could technically still crawl and index your pages in Google without a block on that directory. The benefit of doing it this way for me is to cut out the hassle of re-syncing the database and correcting the permalinks no other reason really 🙂 – for live sites that are already running on a url I still have to develop in a similar way to you and have the agro of the re-syncing.
This is just an attractive alternative that uses the wp core to login also, users can get familiar with the wp login process 😉
Hi Elliott
Very interesting article, thanks for sharing. This is definitely the way I will try when developing my next WP site. So much cleaner than migrating the site and setting it up again.
Will
Thanks for your comment Will, it sure is easier.
Hi Elliott
Very interesting article, thanks for sharing. This is definitely the way I will try when developing my next WP site. So much cleaner than migrating the site and setting it up again.
Will
Thanks for your comment Will, it sure is easier.
I do think I had a site crawled recently in that way. I think I’ll give it try on a site I’m building locally at the moment. I guess that is where the real benefit is. I have been caught out showing a site to a client and the images are missing in places as to me they are still reading from my hard drive as I’ve missed a few links. I do check every site on the iPad now but you are right, it would save that whole issue altogether.
Thanks for sharing this Elliott.
You’re welcome.
I’m sure you already know this but, just make sure you disallow the root in the robot.txt and you should be fine:
User-agent: *
Disallow: /
Don’t forget to change to Allow: / once the site is live.
I do think I had a site crawled recently in that way. I think I’ll give it try on a site I’m building locally at the moment. I guess that is where the real benefit is. I have been caught out showing a site to a client and the images are missing in places as to me they are still reading from my hard drive as I’ve missed a few links. I do check every site on the iPad now but you are right, it would save that whole issue altogether.
Thanks for sharing this Elliott.
You’re welcome.
I’m sure you already know this but, just make sure you disallow the root in the robot.txt and you should be fine:
User-agent: *
Disallow: /
Don’t forget to change to Allow: / once the site is live.
Hey,
Read your post and it’s pretty interesting. A nice and professional way to do things. Will perhaps try this in the future. Thanks for this, Elliot
🙂
You’re welcome Li and thanks for your comment 🙂
Hey,
Read your post and it’s pretty interesting. A nice and professional way to do things. Will perhaps try this in the future. Thanks for this, Elliot
🙂
You’re welcome Li and thanks for your comment 🙂
Hi,
For those that don’t want to get too techy or code files, this is a nice WP plugin to handle maintenance and can be used when you need to take the site offline in future.
http://wordpress.org/extend/plugins/cgc-maintenance-mode/screenshots/
Dan
Thanks for your comment Dan, very useful share.
Hi,
For those that don’t want to get too techy or code files, this is a nice WP plugin to handle maintenance and can be used when you need to take the site offline in future.
http://wordpress.org/extend/plugins/cgc-maintenance-mode/screenshots/
Dan
Thanks for your comment Dan, very useful share.
Will definitely try this some day, I usually use the Maintenance Mode plugin though 😀
Hey thanks for stopping by Todd.
Yup, I’ve used the Maintenance Mode plugin myself and it’s a very useful plugin but, when it comes to adding that little touch of branding I find the manual option better.
Agreed, the little credit in the corner can often be a bit sucky 🙂 but it’s dead easy to implement if you’re only showing a client amendments back and forth.
Will definitely try this some day, I usually use the Maintenance Mode plugin though 😀
Hey thanks for stopping by Todd.
Yup, I’ve used the Maintenance Mode plugin myself and it’s a very useful plugin but, when it comes to adding that little touch of branding I find the manual option better.
Agreed, the little credit in the corner can often be a bit sucky 🙂 but it’s dead easy to implement if you’re only showing a client amendments back and forth.
This is exactly the third posting, of yours I actually
went through. Nonetheless I personally love this 1,
“Developing a WordPress site on a live url” the most.
All the best -Melodee
I’m glad you’ve found this site useful Melodee.
This is exactly the third posting, of yours I actually
went through. Nonetheless I personally love this 1,
“Developing a WordPress site on a live url” the most.
All the best -Melodee
I’m glad you’ve found this site useful Melodee.
Hi Elliott,
Very nice way of doing this. I hate the aggro of the migration too. My question would be if there is a working site on the url, but *not a WP site, theoretically redirecting visitors to the existing site would allow the development to take place ‘cloaked’ as it were. Meaning the existing site functions as usual while the WP site is developed in the background. Rather than having to put up some kind of holding page. Would this work? I guess not if the site uses another CMS like Joomla or? But if the original site were html based?
Thanks for the tips btw 🙂
I depends how the server is set up, if it’s running apache and the current CMS is using PHP it might cause an issue if the current site needs to stay active, my suggestion would be to use a sub domain eg: stage.yourdomain.co.uk then you can develop the site in its own directory, once you are ready to go live you can move the files in to the root and use a search and replace script like interconnectit’s search and replace database tool.
Hope that answers your question.
Hi Elliott,
Very nice way of doing this. I hate the aggro of the migration too. My question would be if there is a working site on the url, but *not a WP site, theoretically redirecting visitors to the existing site would allow the development to take place ‘cloaked’ as it were. Meaning the existing site functions as usual while the WP site is developed in the background. Rather than having to put up some kind of holding page. Would this work? I guess not if the site uses another CMS like Joomla or? But if the original site were html based?
Thanks for the tips btw 🙂
I depends how the server is set up, if it’s running apache and the current CMS is using PHP it might cause an issue if the current site needs to stay active, my suggestion would be to use a sub domain eg: stage.yourdomain.co.uk then you can develop the site in its own directory, once you are ready to go live you can move the files in to the root and use a search and replace script like interconnectit’s search and replace database tool.
Hope that answers your question.
This post has been updated to include an overall function that applies to the whole theme rather than an individual template.
This post has been updated to include an overall function that applies to the whole theme rather than an individual template.
Oh my goodness! Incredible article dude! Thank you, However I am having difficulties with your
RSS. I don’t know why I can’t join it. Is there anybody else getting similar RSS issues?
Anyone that knows the solution will you kindly respond? Thanx!
!
Sorry it wasn’t enabled, it’s now available via the sidebar. Happy reading and thanks for your subscription.
Oh my goodness! Incredible article dude! Thank you, However I am having difficulties with your
RSS. I don’t know why I can’t join it. Is there anybody else getting similar RSS issues?
Anyone that knows the solution will you kindly respond? Thanx!
!
Sorry it wasn’t enabled, it’s now available via the sidebar. Happy reading and thanks for your subscription.
Hi Elliott, I just tried to use this method for my fresh wp 3.6 installation. I used your updated method, i.e.
[code]
function sthn_header_redirect() {
if ( !is_user_logged_in()) {
get_template_part(‘holding’);
exit(0);
}
}
add_filter(‘wp_headers’, ‘sthn_header_redirect’);
[/code]
and i got an blank page. Later I figured out that it should be ‘holdingpage’ instead of ‘holding’ on third line. And bang.. it shows me the Coming soon page.
Now the problem is that when I log in to wp as admin and click on ‘visit site’ it still shows me holding page (coming soon page)
Please help.
Without seeing the full code it’s difficult to say, what do you see if you enable wp_debug in the config.php file?
[code]define(‘WP_DEBUG’, true);[/code]
Hello Elliott,
My fault… It was not working due to cache…
once logged out and then it was working ..
Glad you managed to get things sorted.
Hi Elliott, I just tried to use this method for my fresh wp 3.6 installation. I used your updated method, i.e.
[code]
function sthn_header_redirect() {
if ( !is_user_logged_in()) {
get_template_part(‘holding’);
exit(0);
}
}
add_filter(‘wp_headers’, ‘sthn_header_redirect’);
[/code]
and i got an blank page. Later I figured out that it should be ‘holdingpage’ instead of ‘holding’ on third line. And bang.. it shows me the Coming soon page.
Now the problem is that when I log in to wp as admin and click on ‘visit site’ it still shows me holding page (coming soon page)
Please help.
Without seeing the full code it’s difficult to say, what do you see if you enable wp_debug in the config.php file?
[code]define(‘WP_DEBUG’, true);[/code]
Hello Elliott,
My fault… It was not working due to cache…
once logged out and then it was working ..
Glad you managed to get things sorted.