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.
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.
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.
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.
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.
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
301
302
503
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.