Activate the Default Maintenance Mode with Code

For short-term downtime (less than an hour or so), you might not want to go through the trouble of setting up a custom maintenance mode page.

In that case, you can use WordPress’s default maintenance mode page to let visitors know you’ll be right back.

 Open the functions.php File

Look for the file called Theme Functions or functions.php. With functions.php open in the editor, copy all of the code inside the file and save a copy of it to your desktop. Then, scroll to the bottom of the file and add the following snippet:

function wp_maintenance_mode() {
if (!current_user_can('edit_themes') || !is_user_logged_in()) {
wp_die('<h1>Under Maintenance</h1><br />Website under planned maintenance. Please check back later.');
}
}
add_action('get_header', 'wp_maintenance_mode');

This is the default WordPress maintenance mode setting and message. If you want to edit what it says, replace this bit with your own wording.

As a logged-in user, you won’t be able to see maintenance mode when you visit the website. That’s so you can keep working and previewing your changes.

You want to make sure it’s been activated though.

To do this, you can either log out of WordPress and visit the website or you can open it in a completely new browser.

«
»
ACF (3)
Admin Column (4)
Breadcrumbs (2)
CSS (6)
Custom post types (4)
Custom Taxonomies (3)
Customizer (4)
Hooks & Filters (3)
Jquery (9)
LAMP (10)
Login (5)
Meta boxes (6)
Multisite (2)
My Code (1)
Open Graph Meta Tags (1)
Redirects (2)
SEO (4)
Theme Building (5)
Title Tags (2)
Typography (3)
Uncategorised (54)
User Roles & Capabilities (2)
White labeling (9)
Working with Images (11)
Working with videos (2)
WP Database (1)