Kill Your WordPress Site While Doing Maintenance

in WordPress Security

When you make changes to your site such as a theme change you need to close down your site so you can make the change without your visitors seeing any bugs or problems you are facing.

In this article I will show you how you can close down WordPress for all visitors apart from the admin user.

Website Maintenance

If something has gone wrong with your site or you are making some large changes you should really put the site down before making the changes. There are a number of ways to do this one of the ways is to use the htaccess file to redirect all visitors to a under construction page.

But the problem with this is that it will also stop the admin of the site from logging in to check that the changes have been successful. You can put in some htaccess login to check IP addresses, or a simple way is doing it all in WordPress.

Code To Shut Down WordPress For Everyone Except For The Admin

Put the following code in your functions.php page and it will shut down your site unless you are logged in.

function under_construction_mode() {
    if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
        wp_die('Site is currently under construction please come back soon');
    }
}

add_action('get_header', 'under_construction_mode');

Subscribe To Newsletter

Get weekly updates to your email