RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts</strong | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.69% (5.89%*) • Home Loan Fixed: 5.39% (6.59%*) • Fixed: 5.39% (6.59%*) • Variable: 5.69% (5.89%*) • Investment IO: 5.69% (6.48%*) • Investment PI: 5.39% (6.59%*)

Redirect WordPress Websites That Are Under Construction

Redirect WordPress Websites That Are Under Construction

If you have a website under construction, or you have a temporary page placeholder in place, it's likely that you'll want to deliver a temporary message until your site is ready. While there's a plethora of plugins that will achieve what I've just described, there were none that would do what I wanted them to do. More to the point, there weren't any simple plugins that met the needs of my clients. A temporary page is an opportunity to convert upon the transient visitation, or deliver an engaging message that'll have people checking back in.

As a general rule for any placeholder landing page, you will want to - at the very least - consider rendering the following:

  • Who? Business details. What do you do?
  • Why? Why is your website offline?
  • How? Contact details. Phone number, contact form, email etc.
  • When? When will you be online? Countdown timer, perhaps.
  • Social? Facebook, Twitter, LinkedIn, and other active links.

While we'll provide details on high-converting landing pages in the future, the focus of this article is merely focused on providing an efficient redirect.

Note: The semi-permanent landing page is different to the maintenance page displayed when upgrading WP or plugins. Snippet here.

Simple Site Redirects

In all the functions below you'll need to alter the redirect URL (to your landing page) and header code. Both are discussed below.

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

1
<?php 
2
/*
3
 Redirect WordPress Websites That Are Under Construction
4
 http://www.beliefmedia.com/wordpress-under-construction
5
*/
6
 
7
8
 
9
 if ( ($GLOBALS['pagenow'] !== 'wp-login.php') && (!current_user_can('administrator')) ) {
10
   wp_redirect("http://www.beliefmedia.com/", 302);
11
 }
12
}
13
add_action('template_redirect', 'beliefmedia_under_construction', 1);

In the above example we'll redirect anybody other than a logged in user, or anybody accessing the wp-login.php page. If you chose to include roles other than administrator, the function is modified by way of an array of permitted roles.

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

1
<?php 
2
/*
3
 Redirect WordPress Websites That Are Under Construction
4
 http://www.beliefmedia.com/wordpress-under-construction
5
*/
6
 
7
8
 
9
 $user = wp_get_current_user();
10
 $roles = array('editor', 'administrator', 'author');
11
 
12
 if ( ($GLOBALS['pagenow'] !== 'wp-login.php') && (!array_intersect($roles, $user->roles)) ) {
13
   wp_redirect("http://www.beliefmedia.com/", 302);
14
 }
15
}
16
add_action('template_redirect', 'beliefmedia_under_construction', 1);

If you're anything like us an enjoy an arsenal of web properties, of you have a domain name library, you might have a single page (upon which you'll redirect all others) to process and display an appropriate message.

This first function is used on the source website.

1
<?php 
2
/*
3
 Redirect WordPress Websites That Are Under Construction
4
 http://www.beliefmedia.com/wordpress-under-construction
5
*/
6
 
7
8
 
9
 $user = wp_get_current_user();
10
 $roles = array('editor', 'administrator', 'author');
11
 
12
 /* Redirect string */
13
 $redirect = str_replace(array('+', '/'), array('-', '_'), base64_encode(get_bloginfo('url')));
14
 
15
 if ( ($GLOBALS['pagenow'] !== 'wp-login.php') && (!array_intersect($roles, $user->roles)) ) {
16
   wp_redirect("http://www.beliefmedia.com/landing/under-construction?redirect=$redirect", 302);
17
 }
18
}
19
add_action('template_redirect', 'beliefmedia_under_construction', 1);

Destination Page Code

This article previously showed how to discriminately redirect to different pages. That code will be included back in soon.

PHP Code

Used outside of WordPress, the following function may be used.

1
<?php 
2
/*
3
 Redirect WordPress Websites That Are Under Construction
4
 http://www.beliefmedia.com/wordpress-under-construction
5
*/
6
 
7
8
 
9
 /* Redirect string */
10
 $redirect = str_replace(array('+', '/'), array('-', '_'), base64_encode($url));
11
 
12
 header("Location:http://www.beliefmedia.com/landing/under-construction?redirect=$redirect", 302);
13
}
14
 
15
/* Redirect */
16
beliefmedia_under_construction($url = "http://www.aviationtheory.com/");

The function must be called before any content is rendered to your page.

HTTP Header Codes

There's a number of header codes that could be used for the redirect. We've reproduced the most common header codes below (the 302 and 503 header code are most commonly used).

200

Standard response for successful HTTP requests.

301

This and all future requests should be directed to the given URI.

302

Found. This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily").

503

The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state. This code generally stops search engines from indexing the site.

Considerations

  • Use the inbuilt maintenance feature of WordPress to create a single maintenance page.
  • See also: Create a Custom Maintenance Page (Upgrading Plugins & Themes).
  • The redirects can also be applied the page or post level (which is what we're using when rewriting and porting articles over from Internoetics). We'll be sharing these details another time.

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment