Making an under maintenance page (without using plugins)
There are a bazillion plugins that does this. And every time I use one, I end up spending hours trying to style the message (and logo and background) to fit the styling of the page.
So I was wondering if I could make one easily myself, by using this function:
function custom_maintenance_page() {
if ( ! is_user_logged_in() ) {
if( $_SERVER['REQUEST_URI'] != '/under-maintenance/' ){
wp_redirect( 'https://example.org/under-maintenance' );
}
}
}
add_action( 'template_redirect', 'custom_maintenance_page' );
And then making a new page, with a custom page template, with the 'Under Maintenance'-message. And also, - I could add some CSS like this:
body.page-template-page-under-maintenance {
header,
footer {
display: none !important;
}
}
Upsides:
- The styling for the page is the same, so Google Analytics, stylings and all that are the same.
- It's quick and easy to implement.
- It's not relying on 3rd party code.
- The customer can still work on the site, when they're logged in.
Downsides
- People would be able to remove the
display: none
and see the header and footer. However, - if the visit other pages, then they're redirected to the same one, since they're not logged in. - The API is still open.
My question is... Am I missing an obvious flaw in this? Or would this work alright?
Topic wp-redirect functions redirect maintenance Wordpress
Category Web