How To Update WordPress Plugins Automatically Without Using Plugin

While running a WordPress website, it is just impossible to stay without plugins. A number of useful plugins are available which help us to make websites better. And of course, it is a good practice to use those plugins. At the same time, it becomes hectic to update WordPress plugins. Plugin authors regularly update plugins for better security and new features. Whenever new updates available for single or more plugins, we got notifications for the same.

Updates Notification

The normal way of updating plugin is to go to the Plugins page and click on an update now link which new version is available.

Update Now Link

You need to click on each update now link to the plugins. Basically, you are updating plugins one-by-one by this process.

Alternatively, we can choose the bulk action to update the multiple plugins in one go.

Update WordPress Plugins In Bulk

This process of updating plugins we need to apply regularly. As it is a must-do operation, we recommend using an automated system for it. Keeping this process automatic saves us a time for other important stuff.

That being said, let’s take a look at how to update WordPress plugins automatically.

Update WordPress Plugins Automatically

Definitely some plugins available on the repository which allow us to do the update process automatic. But, we always recommend using the fewer plugins on the WordPress website. If something can be done with a little piece of code, then it is always better not to use plugins. As the number of plugins increases, your application becomes heavier and adds an extra space on the server.

We can update WordPress plugins by writing a little piece of code. It has two parts.

  • Update all plugins
  • Update specific plugins

It may happen that you did customization in the specific plugin and now you don’t want to update it anymore. Although customizing plugin is not a good practice, in some of the cases it can happen. So choose either one process below as per your requirements.

Update All Plugins

WordPress provides a filter auto_update_plugin which is used for updating all plugins automatically. All you need to do is open your active theme’s functions.php file and place the below code at the end of a file.

add_filter( 'auto_update_plugin', '__return_true' );

After placing the above code, whenever WordPress core system checks for new updates it will automatically update plugins which new version is available.

Note: It’s not the case that after adding the above code all plugins updated immediately. You need to wait up to 12 hours. It’s a WordPress software which runs periodically and performs such tasks.

Update Specific Plugins

If you are looking to update specific plugins automatically, then also we need to use the same filter auto_update_plugin but in a different way.

Let’s say we have to update 2 plugins Yoast SEO and WP-Optimize. So first, we need to have slugs of these plugins. You can get the slug of a plugin from the URL of plugin page on a repository.

For Yoast SEO, plugin page URL is https://wordpress.org/plugins/wordpress-seo. And here slug is wordpress-seo.

Same with WP-Optimize, URL is https://wordpress.org/plugins/wp-optimize. So the slug is wp-optimize.

For making updating process automatic for these 2 plugins, our code in functions.php is as follows:

//update specific plugins automatically
function auto_update_specific_plugins ( $update, $item ) {
    // Array of plugin slugs to always auto-update
    $plugins = array ( 
        'wordpress-seo',
        'wp-optimize',
    );
    if ( in_array( $item->slug, $plugins ) ) {
        return true; // Always update plugins in this array
    } else {
        return $update; // Else, use the normal API response to decide whether to update or not
    }
}
add_filter( 'auto_update_plugin', 'auto_update_specific_plugins', 10, 2 );

That’s it! I hope you understand how to update WordPress plugins automatically. Please share your thoughts in the comment section below. You may also like to read our popular article How to Load WordPress Post With AJAX.

If you liked this article, then please subscribe to our YouTube Channel for video tutorials.

Leave a Reply

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