In a previous post on WordPress Plugins I use while developing a WordPress website I mentioned WP Maintenance Mode which blocks public access to the website and returns an HTTP status code of 503 for search engines. But did you know you can change the returned HTTP status code?
You might be wondering why anyone would want to do this. Well, recently we were working on a website that should only be accessed by those with valid login credentials. Since the client wanted to be able to add new users down the line, we couldn’t use
.htaccess password protection and instead had to rely on WordPress’ own User credentials. We had already enabled WP Maintenance Mode while developing the website so we thought we’d just leave it enabled post-launch but change the Under Construction screen.
And everything worked until we set up our Website Monitoring tools. Because the website was now returning a 503 status code our monitoring tools thought the website was down when in fact it wasn’t. The thought of being flooded by emails proclaiming “You’re Websitez Is Downzzzzz0r !!1!1one!” wasn’t very appealing so we dug around the WP Maintenance Mode PHP code until we found what we were looking for: a WordPress filter that changed the returned HTTP status code.
By default, WP Maintenance Mode will return a 503 status code. For our purposes, we decided that we could safely return a 200 status code (effectively saying “the website is up and running fine!”). Here’s what we put in our
// Adjust the status code returned by WP Maintenance Mode. add_filter( 'wpmm_status_code', 200 );
And just like that our Website Monitoring tools worked again.
Knowing your tools and how they work
There are so many options to build websites today and platforms like WordPress make it easy by giving you an array of Themes and Plugins to install. But that will only take you so far. Building websites also means knowing about the tools you are using and how they work in order to produce the kind of website you want.
At Caveena Solutions we combine our deep knowledge of website building with WordPress (our main tool of choice) and PHP (the language WordPress uses) to deliver websites that meet the functional criteria of our clients. Do you have a website that you’ve always wanted to build? Contact Caveena Solutions and we’ll work with you to bring it into reality.