Blog / WordPress/ How to Disable WordPress Automatic Updates and Hide Notifications

How to Disable WordPress Automatic Updates and Hide Notifications

WordPress 自动更新与更新提示的禁用方法详解

How to Disable WordPress Automatic Updates

While WordPress automatic updates help keep your site secure, there are specific scenarios (such as highly customized sites or environments requiring strict version control) where you may need full control over update timing. Here are two methods to disable automatic updates.

Method 1: Modify the wp-config.php File

Locate the wp-config.php file in your site's root directory. Before the line that reads /* That's all, stop editing! Happy publishing. */, add the following constant definition:

/** Disable all WordPress automatic updates */
define('AUTOMATIC_UPDATER_DISABLED', true);

This method globally disables automatic background updates for the core, themes, plugins, and translation files.

Method 2: Add a Filter to the Theme's functions.php File

Alternatively, you can add the following code to the end of your active theme's functions.php file:

// Disable WordPress automatic updates
add_filter('automatic_updater_disabled', '__return_true');

This method uses a WordPress filter hook and achieves the same effect as Method 1.

How to Hide Update Notifications in the WordPress Admin

After disabling automatic updates, update notifications will still appear in the WordPress admin dashboard and admin bar. If you wish to hide these notifications completely, you can use the following code.

Note: The original example used the deprecated create_function function (removed in PHP 7.2+). We provide a more compatible, modern approach.

Recommended Method: Using Anonymous Functions (Compatible with PHP 5.3+)

Add the following code to your active theme's functions.php file:

// Completely hide all update notifications in the WordPress admin
add_filter('pre_site_transient_update_core', function($a){ return null; }); // Hide core updates
add_filter('pre_site_transient_update_plugins', function($a){ return null; }); // Hide plugin updates
add_filter('pre_site_transient_update_themes', function($a){ return null; }); // Hide theme updates

// Remove scheduled tasks that check for updates
remove_action('admin_init', '_maybe_update_core');
remove_action('admin_init', '_maybe_update_plugins');
remove_action('admin_init', '_maybe_update_themes');

Original Method (Outdated)

The original code using create_function was effective in older versions but has security and compatibility issues and is not recommended for new projects.

Important Reminder: Disabling update notifications means you will not see visual alerts in the admin for new versions. You must regularly check for updates manually via other means (e.g., subscribing to the official blog, using monitoring tools) to ensure your site's security.

Summary and Best Practices

  • Selective Disabling: Consider using the WP_AUTO_UPDATE_CORE constant for more granular control (e.g., disabling only core auto-updates) instead of a complete shutdown.
  • Use a Child Theme: If modifying a theme's functions.php file, always do so within a child theme to prevent your changes from being overwritten during theme updates.
  • Plugin Solution: Users unfamiliar with code can consider using plugins like 'Easy Updates Manager' to manage update settings via a graphical interface.
  • Security Responsibility: After disabling automatic updates, you assume the responsibility of manually updating WordPress core, themes, and plugins in a timely manner to patch security vulnerabilities.

Post a Comment

Your email will not be published. Required fields are marked with *.