Maintenance Mode is one of the most important part of website for revoke access to user or visitor when need. Nowadays you will see most popular website are take schedule maintenance for updating or fixing or something else. In WordPress there is lots of plugin to enable maintenance mode or coming soon mode, but you may not like to use unusual plugin if you can manage with simple coding. yes WordPress has beautiful way to do that, by action hook you can stop loading site content on front-end and replace by your custom message, so basically your visitors will see the message instead of site content.

How to enable maintenance mode on WordPress?

Here is the simple code you can use under your theme functions.php file to enable Maintenance Mode instantly.

add_action('get_header', 'maintenance_mode');

function maintenance_mode(){

  ob_start();
    ?>
    <div class="maintenance">

        <div class="logo">
            <img src="https://i.imgur.com/flfP9mY.png" />
        </div>
        <h2>Sorry, we are taking some break.</h2>
        <p>We will back soon after some quick update. please stay with us and check after a while.</p>
    </div>

    <style type="text/css">

        @import url('https://fonts.googleapis.com/css?family=Open+Sans:400,800');

        html {
            background: #ddddddb3;
            font-family: 'Open Sans', sans-serif;
        }

        .maintenance {
            width: 600px;
            background: #fff;
            margin: 0 auto;
            padding: 60px;
            margin-top: 40px;
        }
        .maintenance .logo {
            width: 200px;
            overflow: hidden;
            text-align: center;
            margin: 0 auto;
            margin-bottom: 46px;
        }

        .maintenance .logo img {
            width: 100%;
        }

        .maintenance h2 {
            font-size: 18px;
            margin: 20px 0;
            display: block;
            font-weight: bold;
        }
        .maintenance p {
            font-size: 15px;
            margin: 15px 0;
            display: block;
        }

    </style>

    <?php

  $html = ob_get_clean();

  wp_die($html, 'Site title here', '');
}

How to stop maintenance mode?

When you don’t need to enable maintenance mode just simply commented out the following line on above code, so it will stop working.

//add_action('get_header', 'maintenance_mode');

 

 

Here is the output of that code when someone trying to visit your website.

enable maintenance mode on WordPress

 

How to edit theme functions.php file from dashboard?

You can easily edit theme functions.php file via WordPress admin dashboard.  you need to go following menu

Appearance > Editor > By default it will open with style.css for edit.

you will need to click on “Theme Functions” from right list if files to load theme functions.php file on editor.

here is the screenshot for “Twenty Twelve” theme

How to edit theme functions.php

Most of the plugins loaded unusual scripts and style files that’s must effect on site loading issue as well as SEO performance. i hope you will love this.