How to Auto-Update WordPress Plugins and Themes (in Code)
![](https://iotvnaw69daj.i.optimole.com/w:870/h:400/q:mauto/rt:fill/g:ce/f:avif/https://wpshout.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-02-at-12.10.22-PM.png)
Keeping WordPress core up-to-date has become so easy in the last few years that I barely even thing about it. Keeping WordPress plugins and themes up-to-date is currently still a more complex task. There are plugin-based solutions for it, but in this video we cover the method that’d be more favored by those who love writing PHP: the code that makes WordPress auto-update your plugins and themes.
There is some need for obvious provisos here: don’t auto-update plugins and themes that you don’t trust to keep working. Don’t enable auto-updates this way if you don’t have a solid backup system in place. Don’t use this solution of PHP-based auto-updates if your site looking weird when a plugin update doesn’t work will cause you (or someone else) to get fired.
With all those reasons why not, there’s one really good reason to do it: an updated WordPress plugin is more secure well over 95% of the time than an un-updated one. That means that while this isn’t an unquestionable win, it usually is one. Here’s how to do it on video:
How to Enable WordPress Plugin Auto-Updates in PHP Code
- Create your plugin or theme functions.php file. The Codex recommends that you use an
mu-plugin
to do that — that is a “must-use” plugin that WordPress always has on. But WordPress will honor this code if it’s in an enable plugin or theme as well. - Put in the line of code:
add_filter( 'auto_update_plugin', '__return_true' );
- Put in the line of code:
add_filter( 'auto_update_theme', '__return_true' );
- Make sure this code is somewhere it will run. If you’ve created this as a new plugin in the
mu-plugins
directory, it will. If you’ve enabled the (normal) plugin, it will. If you have it infunctions.php
of your currently running theme, it will.
Great video, thanks.
Your two lines update plugins and themes.
How do you recommend we set up WP to auto-update any major or minor WordPress release?
FYI: You link for “are plugin-based solutions for it,” is.. wrong 😉 if you know what I am saying.
Please fix.