< Back to blog

Code Snippet: Activate WordPress maintenance mode without a plugin

Do you want to put your WordPress website in maintenance mode while you make some changes to the website without a plugin?

You can do so by adding the following snippet to your theme’s funtion.php.

// Activate WordPress Maintenance Mode
function activate_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', 'activate_maintenance_mode');

Code not working? Let me know below.