Maintenance mode

tdrayson

I wanted a way to enable a maintenance page without adding an extra plugin and giving me control over the design/functionality.

I also wanted to be able to share a link with a password in the url for clients to view the website during development.

1. Adding our settings

We are going to be using an array to store our maintenace mode settings.

Add the below to your functions.php or code snippet plugin.

PHP

        /*
 * tct_maintenance_settings
 *
 * @function Settings for maintenace page
 * @author Taylor Drayson
 * @since 10/04/2023
*/
function tct_maintenance_settings(){
    return [
        'enabled' => true,
        'page' => 99, // coming soon page ID
        'password' => 'password123', // our password
		'excludes' => ['ct_builder', 'bricks'] // Exclude query params
    ];
}
      
Copy

We have 3 options

  • enabled – this determines whether our maintenance mode page should be active or not
  • page – this is the ID of the page you want to display
  • password – this is the password used in the url to bypass the maintenance mode
  • excludes – this is where you can exclude query params for password being appeneded in step 5.

2. Maintenance condition

Next we need to create a boolean function to check if we should be showing our maintence page or not.

Add the below to your functions.php or code snippet plugin.

Members content only

Become a SnippetClub member to gain instant access to this tutorial plus tons more premium content.

Already a member? Log in below.

Login Form

👋🏻 Weekly Tutorial Digest

I send out a weekly newsletter with links to new tutorials written in the last week, you can subscribe below.

Newsletter

🔒I won't send you spam, I promise