Wordpress: Custom Maintenance Mode
Keep your visitors informed during site updates with a custom maintenance mode page using this WordPress snippet.
Setting up a custom maintenance mode page can help communicate effectively with visitors during site updates or when maintenance is required. This snippet enables a custom maintenance mode in WordPress.
Using the wp_loaded
hook, the snippet checks if a custom maintenance mode is active. If active, it displays a maintenance page instead of the regular site content, preventing access to the site's backend and frontend.
This custom page can be designed to match the site's branding and include information about the maintenance duration and contact information, improving user experience during downtime.
The snippet also includes a method for admins to bypass the maintenance mode by checking user roles, ensuring that site management can continue uninterrupted.
Best practices for implementing a user-friendly maintenance mode are discussed, including how to minimize SEO impact and keep users informed about site status.
Snippet Code
Version Compatibility
This snippet is effective with WordPress 3.0 and later, where the wp_loaded hook allows for early intervention in the page load process.
Required PHP Version
PHP 5.3 or higher
Wordpress Core Functions Used
Use Cases
- site updates
- user communication
- custom pages