Developing a WordPress site on a live url

Developing a WordPress site on a live url

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:

<!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>

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.

<?php
 /* Template Name: Custom Page */
 if ( !is_user_logged_in()) {
 get_template_part('holdingpage');
 exit(0);
 }
 get_header(); ?>

*** 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:

function sthn_header_redirect() {
 if ( !is_user_logged_in()) {
 get_template_part('holdingpage');
 exit(0);
 }
 }
 add_filter('wp_headers', 'sthn_header_redirect');

*** 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:

//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-&gt;user_level == 0)
{
wp_redirect( home_url() ); exit;
}
}

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.

// hide adminbar
if (!current_user_can('administrator')) :
show_admin_bar(false);
endif;

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:

&lt;?php echo wp_logout_url( home_url() ); ?&gt;

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.

About

Graphic designer, web designer, frontend coder and partner at Square One a graphic and web design company in Cheltenham, interested in astronomy and sometimes cooks! Favourite cuisine includes Italian and Wordpress.

Discussion 24 Comments

  • G’dam!! Note to self: Be very careful when tweeting from multiple accounts, don’t get your business mixed up with your hobbies! 7 mins ago
  • This evenings ride bit.ly/1uFOutf if anyone would like to join us we meet outside #Woodmancote School (Station Rd) 6pm prompt 9 mins ago
  • what a disappointment, I hear #LFC did alright though… in the 90th minute O_o 11 hours ago
  • Shocking defence #arsenal >< 11 hours ago
  • oh for god sakes!! you got caught off guard Gibbs! :( 12 hours ago
twitterbird

FASTSIGNS

I would like to express my thanks for the help you and Elliott gave us during the time when our designer was on leave. The service you provided was swift accurate and efficient – where creativity was required we were able to impress our clients with your design capabilities and I will not hesitate to … read more

ipad