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.
/* * 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 notpage
– this is the ID of the page you want to displaypassword
– this is the password used in the url to bypass the maintenance modeexcludes
– 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.