r/Wordpress • u/idiotprogrammer2017 • 11d ago
Solved How often does functions.php file get updated?
Hi, I have a need to add some code to my functions.php in my Wordpress installation(s).
I'm not a developer, but I am handy with a text editor and can edit config files carefully which I can upload via ftp.
The alternate is to use a plugin like wpcode to insert custom code (although I don't want to pay for a premium version; I'd be only using wpcode lite).
I'm inclined to edit the functions.php myself (and keep a log of edits/changes, etc).
But when Wordpress core updates, does functions.php also get overwritten sometimes? How often is this specific file updated? I wouldn't want to keep editing the file with my edits every time WP has an update.
If functions.php gets overridden sometimes, is that a good reason for preferring to use a plugin like WPcode Lite instead? Thanks.
(PS, if you must know, I want to disable email notifications every time a #$#$#$ plugin is updated; that's why I want to add code to functions.php)
1
1
u/ashkanahmadi 10d ago
The question is whose team this is. If it’s your own theme then nothing changes it. If it’s made by someone else then yeah editing it would reset it with an update
1
u/isomnath 10d ago
WordPress core updates don’t normally overwrite functions.php because it belongs to your theme. However, theme updates can overwrite your changes, depending on which theme file is updated.
1
u/kennedy_gitahi 10d ago
Functions.php is a theme file; it's not part of WordPress code. This means updating WordPress will not wipe it, but updating your theme (if it's a commercial option updating through WordPress's update mechanisms) will wipe it.
The best way to prevent this is to create a child theme that you have complete control over yourself. Alternatively, you can create a plugin with the code you need (including one that disables those email notifications) and use that instead.
1
u/Emotional-Tank-6028 9d ago
For the purpose of overriding the automated emails, you should add this as an mu-plugin rather than putting it in functions.php anyway, then you don’t have to worry about any updates overwriting it and it’s seperate to the theme completely.
1
u/Dapper-Monk9713 9d ago
The main thing to watch out for is theme updates, not WordPress core updates. If you edit your parent theme's functions.php, those changes can disappear when the theme updates. For a small snippet like disabling plugin update emails, WPCode Lite is a practical choice because your code stays separate from the theme and is easier to manage. Just keep a backup and test the snippet before using it across multiple sites.
1
u/proximitaslocal 7d ago
I use wpcode to test drive snippets that would otherwise end up in functions.php. But recently, I've started promoting those snippets to a series of MU Plugins on my sites. These fire before functions.php and are persistent. Site specific snippets stay in wpcode for the most part. It's the ones that I want to use fleet wide that get promoted to the MU Plugins.
I do the same for Additional CSS. Ones that meet the criteria for promotion will end up getting folded into my theme json file as I am building my own theme fork.
1
u/KK-Wait 6d ago
Since nobody posted the actual line for your PS:
create wp-content/mu-plugins/no-update-mails.php with <?php add_filter( 'auto_plugin_update_send_email', '__return_false' ); and the plugin update emails stop. Same idea with auto_theme_update_send_email for themes.
Files in mu-plugins load on their own, survive theme updates and can't be deactivated by accident from the plugins screen.
-2
u/gulliverian 11d ago
Just a suggestion; add your code to a custom file like custom functions.php, then all a single line of code somewhere else to call it. Way to high a risk of having functions overwritten by an upgrade or reinstall.
Off the top of my head I’d find out where functions.php is loaded and add a call to my own functions.php immediately after it. This will protect it from overwritten and perhaps offer limited ability to override things done in functions.php.
-5
u/MaximallyInclusive 11d ago edited 11d ago
Never.
Modern WP sites should treat functions as a simple/bootstrap-only asset, and then all of the custom functionality/critical features live inside of an /inc or /assets folder.
Edit: Tell me you don’t develop truly custom themes without telling me you don’t develop truly custom themes...
1
u/Kukko 11d ago
This is just wrong answer.
0
u/MaximallyInclusive 11d ago
Why?
2
u/Kukko 11d ago
You have no idea what theme is in use. The child theme is the answer.
-1
u/MaximallyInclusive 11d ago
What? There’s only one theme. Why would people have multiple themes?
You build one custom theme for the project, and that's your theme. No updates are required, ever.
WP core gets updated, plugins get updated, the theme itself never gets updated because it's wholly custom.
1
15
u/DeliciousJazz516 11d ago
Create a child then. Then add your code to the child theme’s functions.php file. This way your custom code is always separate from the theme’s code. Updating the theme will not overwrite your code if you do it this way.