WP Maintenance Mode Snippet without Plugin

Code Snippet Purpose

There are many maintenance mode plugins available for WordPress. Some themes also offer built-in maintenance mode feature that you can activate when needed. However, you can use a quick code snippet to put your site in maintenance mode without any plugin and if you do not have this feature in your theme.

Template to Edit

You have to edit your theme’s functions.php file and add the below snippet.

Maintenance Mode Code Snippet

Below code will show maintenance mode for all users not logged into your site.

function maintenace_mode() {

if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
add_action('get_header', 'maintenace_mode');

It should look like below on the editor.

Maintenance Mode Code in Functions PHP File
Maintenance Mode Code in Functions PHP File

Testing Maintenance Mode

  • After updating functions.php file, make sure to logout of your WordPress admin panel.
  • Open the site’s home page or any other page in the browser.
  • You should see a quick maintenance message like below.
Site in Maintenance Mode
Site in Maintenance Mode

Disable Maintenance Mode

Simply go to “Appearance > Theme Editor” and delete the above code from your theme’s functions.php file. Alternatively, use FTP or File Manager to edit functions.php file.

RELATED:  How to Edit wp-config.php File in WordPress?

Leave a Comment