When you start delving a little more deeply into WordPress and want to customize things beyond what is offered by default via the GUI customization options, you enter the world of modifying code to suit your needs. At this point, it’s important to do things correctly. Every WordPress site tells you to be careful and follow these best practices:
- Never modify core WordPress code
- Always create child themes
- Contact the plugin developer for code changes
This is excellent advice. And for the overwhelmingly large part of your WordPress career, you would never actually manually change core code files. But are there situations where this might be necessary? Let’s take a look.
1. Modify Core WordPress Files – NEVER!
In my decade long experience with WordPress, I have never once found a reason to manually modify anything in the WordPress core code. Obviously, I’m not referring to custom plugins in the wp-content folder. I’m referring more to wp-includes, wp-admin, etc. These files contain fundamental functionality in WordPress and typically have nothing to do with display – only logic.
There was one situation I remember years ago, when I thought I would be forced to modify a WordPress core file. It had to do with thread indentation of comments. But in the end, I found a workaround involving a rewrite of the “Reply” link that I was able to encapsulate into a code snippet in functions.php. So I managed to avoid that as well.
Since then, I’ve never had a need to modify core WordPress files. Doing so is dangerous because not only will your changes get overwritten with the next update, it can likely have trickle down effects that you won’t anticipate.
2. Modifying Parent Theme Files – ALMOST Never
Just like the first one, you should avoid modifying main theme files directly. As much as possible, try and use the built-in options for modification. And if you need to make changes that are inaccessible via the theme options, you should create a child theme so that your modifications aren’t overwritten when the parent theme updates.
However, unlike with point 1, I can maybe see some situations where you can safely modify the parent theme. One possibility is that you yourself are the theme’s author! So you know exactly what you’re doing, and there’s no danger of an external update breaking your changes. A second situation might be when you know for a fact that the theme will no longer be updated. Maybe the theme’s author just isn’t active anymore, and you can safely make changes knowing that they will never be lost.
3. Modifying Plugin Files – Sometimes Necessary
The same caveat goes for modifying plugin files – your changes will be overwritten when the plugin updates. But unlike themes, there’s no concept of a “child plugin” since there’s no standard framework for WordPress plugin functionality. So if you want to change something, and the plugin author won’t take your suggestion on board, you have no option but to dig in yourself.
An example: Earlier, I’d written a tutorial on how to defer inline Javascript by changing the type to “module” from “text/javascript”. Unfortunately, much of my inline Javascript is a result of plugins outputting their code. I had no choice but to make the changes directly to the plugin code. One example, is the plugin for showing a Table of Contents via a shortcode. Luckily, this plugin no longer seems to be in active development, so there’s no danger of an update.
Other plugins however, still receive updates. So I maintain a separate notebook file where I list out the changes I’ve made to which files and I have to manually change them back every time one of these plugins gets updated. It’s tedious, but I’ve decided that the additional performance from deferring jQuery is worth it.
And there’s the rub. Modifying files like this always involves a cost in additional maintenance. You’ll have to decide for yourself whether or not the extra hassle is worth it. It often isn’t. But when necessary, you must do so carefully.
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!
Leave a Reply