Vous aimeriez aussi lire...

Whether you’re updating your website, fixing a critical error, or performing routine maintenance, putting your WordPress site into maintenance mode is essential. This temporary state ensures visitors see a professional message instead of a broken or incomplete page. But how do you enable maintenance mode effectively without losing traffic or damaging your SEO?
In this comprehensive guide, we’ll walk you through how to put WordPress into maintenance mode using multiple methods—from built-in features to plugins and manual techniques. You’ll also learn best practices to minimize downtime, keep users informed, and avoid common pitfalls. Let’s dive in!
Why Use Maintenance Mode in WordPress?
Before jumping into the « how, » it’s important to understand the « why. » Maintenance mode serves several critical purposes:
- Improves User Experience: Instead of seeing a broken site, visitors get a clear message explaining the temporary unavailability.
- Protects Your SEO: Search engines like Google penalize sites with frequent errors. Maintenance mode prevents crawlers from indexing incomplete pages.
- Enhances Security: During updates or fixes, your site may be vulnerable. Maintenance mode hides it from potential threats.
- Professionalism: A well-designed maintenance page reflects your brand’s credibility, even during downtime.
Now that you understand its importance, let’s explore the different ways to enable maintenance mode in WordPress.
Method 1: Using WordPress’s Built-In Maintenance Mode
WordPress has a default maintenance mode that activates automatically during core, theme, or plugin updates. However, this mode is basic and only displays a plain message: « Briefly unavailable for scheduled maintenance. Check back in a minute. »
How to Trigger the Default Maintenance Mode
The built-in maintenance mode is triggered when WordPress detects an update process. Here’s how it works:
- When you initiate an update (e.g., WordPress core, plugins, or themes), WordPress creates a temporary file named
.maintenancein your site’s root directory. - This file contains a simple message that displays to visitors.
- Once the update is complete, WordPress automatically deletes the
.maintenancefile, and your site goes live again.
Limitations of the Default Maintenance Mode
While convenient, the default maintenance mode has drawbacks:
- No Customization: The message is generic and lacks branding or additional information.
- No Control: You can’t manually enable or disable it—it only activates during updates.
- No SEO Protection: Search engines may still crawl the site if the maintenance file isn’t properly configured.
For more control, consider the methods below.
Method 2: Using a WordPress Maintenance Mode Plugin
Plugins offer the easiest way to enable a custom maintenance mode in WordPress. They provide advanced features like countdown timers, custom designs, and SEO-friendly settings. Here are the best plugins for the job:
1. WP Maintenance Mode
WP Maintenance Mode is one of the most popular plugins for this purpose. It’s user-friendly and packed with features.
How to Use WP Maintenance Mode
- Install and Activate: Go to Plugins > Add New, search for « WP Maintenance Mode, » and install it.
- Configure Settings: Navigate to Settings > WP Maintenance Mode.
- Enable Maintenance Mode: Toggle the « Activated » switch to « Yes. »
- Customize the Page:
- Add a title, heading, and message for visitors.
- Upload a background image or choose a color scheme.
- Enable a countdown timer for scheduled maintenance.
- Add a subscription form to collect emails during downtime.
- Save Changes: Click « Save Settings » to apply your customizations.
2. Coming Soon Page & Maintenance Mode by SeedProd
SeedProd is another powerful plugin that offers both maintenance mode and coming soon pages. It’s ideal for launching a new site or rebranding.
How to Use SeedProd
- Install and Activate: Search for « SeedProd » in the WordPress plugin repository and install it.
- Create a Maintenance Page: Go to SeedProd > Pages and click « Add New Coming Soon/Maintenance Page. »
- Choose a Template: Select a pre-designed template or start from scratch.
- Customize the Page:
- Drag and drop elements like text, images, and buttons.
- Add a countdown timer or social media links.
- Enable SEO settings to block search engines during maintenance.
- Publish the Page: Click « Save » and toggle the « Enable Maintenance Mode » switch to « Yes. »
3. LightStart – Maintenance Mode, Coming Soon and Landing Page Builder
LightStart is a lightweight yet feature-rich plugin for maintenance mode. It includes GDPR-compliant forms and WooCommerce support.
How to Use LightStart
- Install and Activate: Search for « LightStart » in the WordPress plugin directory.
- Configure Settings: Go to LightStart > Settings.
- Enable Maintenance Mode: Toggle the « Enable Maintenance Mode » option.
- Design Your Page:
- Choose a template or customize the layout.
- Add a progress bar, contact form, or social media icons.
- Set a custom redirect URL for logged-in users.
- Save and Activate: Click « Save Changes » to enable maintenance mode.
Method 3: Manually Enabling Maintenance Mode via .htaccess
If you prefer not to use a plugin, you can enable maintenance mode manually by editing your site’s .htaccess file. This method is best for advanced users comfortable with code.
Steps to Enable Maintenance Mode via .htaccess
- Access Your .htaccess File:
- Connect to your site via FTP (e.g., FileZilla) or your hosting provider’s file manager.
- Locate the
.htaccessfile in your site’s root directory (usuallypublic_html).
- Backup the File: Before making changes, download a copy of your
.htaccessfile as a backup. - Add Maintenance Mode Code: Insert the following code at the top of your
.htaccessfile:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REMOTE_ADDR} !^123.456.789.000 RewriteCond %{REQUEST_URI} !^/maintenance.html$ RewriteRule ^(.*)$ https://yourdomain.com/maintenance.html [R=307,L] </IfModule>Note: Replace
123.456.789.000with your IP address to exclude yourself from the redirect. Replaceyourdomain.com/maintenance.htmlwith the URL of your maintenance page. - Create a Maintenance Page:
- Create an HTML file named
maintenance.htmlin your root directory. - Design the page with a message like: « We’re undergoing maintenance. Please check back soon! »
- Create an HTML file named
- Upload and Test:
- Upload the
maintenance.htmlfile to your root directory. - Visit your site to ensure the maintenance page displays correctly.
- Upload the
- Disable Maintenance Mode: To turn it off, remove the code from your
.htaccessfile and delete themaintenance.htmlfile.
Pros and Cons of the .htaccess Method
Pros:
- No plugin dependency.
- Lightweight and fast.
- Works even if WordPress is broken.
Cons:
- Requires technical knowledge.
- No easy way to customize the page without HTML/CSS skills.
- Risk of breaking your site if the code is incorrect.
Method 4: Using a Custom Function in functions.php
Another manual method involves adding a custom function to your theme’s functions.php file. This approach is useful if you want more control over the maintenance page’s content.
Steps to Enable Maintenance Mode via functions.php
- Access functions.php:
- Go to Appearance > Theme Editor in your WordPress dashboard.
- Select
functions.phpfrom the list of theme files.
- Add the Maintenance Mode Code: Insert the following code at the end of the file:
function custom_maintenance_mode() { if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) { wp_die('<h1>Under Maintenance</h1><p>We’re performing scheduled maintenance. Please check back soon!</p>', 'Maintenance Mode', array( 'response' => 503 )); } } add_action('get_header', 'custom_maintenance_mode'); - Customize the Message: Replace the text inside
wp_die()with your own maintenance message. - Save Changes: Click « Update File » to apply the changes.
- Disable Maintenance Mode: To turn it off, remove the code from
functions.php.
Pros and Cons of the functions.php Method
Pros:
- No plugin required.
- Full control over the maintenance message.
- Works even if WordPress is partially broken.
Cons:
- Requires coding knowledge.
- Risk of breaking your site if the code is incorrect.
- No easy way to exclude specific users or IP addresses.
Best Practices for Using Maintenance Mode
Enabling maintenance mode is just the first step. To ensure a smooth experience for your visitors and search engines, follow these best practices:
1. Inform Your Users in Advance
- Announce the maintenance schedule on your blog, social media, or email newsletter.
- Provide an estimated downtime duration (e.g., « We’ll be back in 2 hours »).
2. Use a Custom Maintenance Page
- Avoid the generic WordPress message. Use a plugin or custom HTML to create a branded page.
- Include your logo, contact information, and a friendly message.
3. Exclude Search Engines
- Use the
503 Service UnavailableHTTP status code to tell search engines your site is temporarily down. - Most maintenance mode plugins handle this automatically.
4. Whitelist Your IP Address
- Ensure you (and your team) can access the site during maintenance by whitelisting your IP address.
- This is especially useful if you’re testing changes.
5. Test Before Going Live
- Enable maintenance mode on a staging site first to ensure everything works as expected.
- Check the page on different devices and browsers.
6. Monitor Your Site
- Use tools like UptimeRobot to monitor your site’s status during maintenance.
- Be prepared to disable maintenance mode quickly if something goes wrong.
Troubleshooting Common Issues
Even with the best preparations, issues can arise. Here’s how to troubleshoot common problems:
1. Maintenance Mode Won’t Disable
Cause: The .maintenance file wasn’t deleted after an update.
Solution:
- Access your site’s root directory via FTP or your hosting file manager.
- Delete the
.maintenancefile manually.
2. Maintenance Page Not Displaying
Cause: The plugin or code isn’t configured correctly.
Solution:
- Clear your browser cache and WordPress cache (if using a caching plugin).
- Check the plugin settings or code for errors.
- Test in a private/incognito browser window.
3. Search Engines Are Indexing the Maintenance Page
Cause: The maintenance page isn’t sending a 503 status code.
Solution:
- Use a plugin like SeedProd or WP Maintenance Mode, which handle SEO settings automatically.
- If using a manual method, ensure your
.htaccessorfunctions.phpcode includes the503status.
Conclusion
Putting your WordPress site into maintenance mode is a crucial step for any website owner. Whether you’re performing updates, fixing errors, or launching a redesign, a well-executed maintenance mode ensures a seamless experience for your visitors and protects your SEO.
Here’s a quick recap of the methods covered:
- Default Maintenance Mode: Simple but limited, triggered during updates.
- Plugins (WP Maintenance Mode, SeedProd, LightStart): Easy to use, customizable, and SEO-friendly.
- .htaccess Method: Manual control, no plugin dependency, but requires technical skills.
- functions.php Method: Customizable, but best for advanced users.
For most users, a plugin like WP Maintenance Mode or SeedProd is the best choice. They offer the right balance of ease of use, customization, and SEO protection. However, if you’re comfortable with code, the manual methods provide more control.
Whichever method you choose, remember to:
- Inform your users in advance.
- Use a branded maintenance page.
- Exclude search engines with a
503
Merci pour cet article détaillé ! J’ai souvent eu des soucis avec la maintenance de mon site WordPress, ce guide va vraiment m’aider.