How to Set a WordPress Site Offline for Maintenance
This snippet will easily let you set your WordPress site offline by using the wp_die
. This is a handy and easy way for you to kill WordPress functions (sets your site offline – but still displays HTML for your visitors) while you perform website maintenance or other website-related services.
*note – in this example we have set the if ( !current_user_can
conditions ex. to limit the wp_die
functions to be executed to non admins only. You can also still access the www.example.com/wp-admin/
login path while this nippet is active.
Instructions
Add this to your functions.php
file.
function wp_snippet_maintenance_mode() { if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) { wp_die( '<strong>Site offline for maintenance!</strong><br/>Hang on - we´ll be right back online.<br/>For contact & support - please refere to: <a href="http://www.wp-snippet.com" target="_blank" rel="noopener noreferrer">http://www.wp-snippet.com</a> !', 'Site Offline For Maintenance', ''); } } add_action('get_header', 'wp_snippet_maintenance_mode');
*Replace any relevant info you wish to be displayed for your visitors
Excellent …