WoocommerceWordpress

Simple Maintenance Mode snippet for wordpress and woocommerce

This code is a WordPress plugin (can also be added in the functions.php file) that creates a maintenance mode page when activated.

No setup needed, just copy and paste !

When the plugin is active, it checks if the current user is not an administrator (using the current_user_can() function with the 'manage_options' parameter). If the current user is not an administrator, WordPress will display a message on the front end of the site stating that the site is under maintenance

Overall, this code is a useful tool for WordPress site administrators who need to perform maintenance tasks on their site without disrupting the user experience for regular visitors.

    
<?php /* Plugin Name: My Maintenance Mode Plugin+++++ Snippet URI: https://wpsnippet.club/snippet/simple-maintenance-mode-snippet-for-wordpress-and-woocommerce Description: Displays a maintenance mode page when activated. Version: 1.0 Author: WP Snippet Club Author URI: https://wpsnippet.club/ */ function my_maintenance_mode() { if ( !current_user_can( 'manage_options' ) ) { wp_die( '<div style="background-image: url(https://images.pexels.com/photos/268533/pexels-photo-268533.jpeg); background-size: cover; height: 100vh; flex-direction: column; display: flex; justify-content: center; align-items: center; position: absolute; top: 0; left: 0; right: 0; bottom: 0;"><h1 style="color:white; ">Site Under Maintenance</h1><p style="color:white;">We are currently performing maintenance on our site. We apologize for the inconvenience we will be back soon.</p></div>' ); } } add_action( 'wp_loaded', 'my_maintenance_mode' ); //comment the line above to disable the maintenance mode ?>

Leave a Reply