Is using Code Snippets instead of a child theme for custom PHP a bad practice?

[ad_1]

Hi everyone,

I’ve recently built a website using Astra/Spectra along with a WooCommerce shop. To add a few customizations, I opted for using code snippets through a plugin, instead of directly modifying the theme files or employing a child theme. I’ve come across numerous discussions suggesting that for adding custom PHP code, creating a child theme is the preferred approach. There’s also some chatter about the potential performance impact when using code snippet plugins.

Personally, I’m quite satisfied with my website’s performance and haven’t encountered any issues. The convenience of managing 30+ well-documented and tagged snippets—easily toggling them on and off and experimenting—is something I really appreciate. However, these discussions have made me wonder if I’m adopting a suboptimal practice by avoiding child themes.

Is leveraging a snippets plugin over a child theme considered bad practice, especially when performance is not currently an issue for me? Should I be considering a migration to using a child theme for the sake of best practices or future-proofing my work?

Would love to hear your thoughts, experiences, or any advice you might have on this. Thanks!

[ad_2]
4 Comments
  1. If it works for your application, you should keep it that way. Personally, I like my customization to be tied closely to either a plugin or a theme, so I’d put them in a child theme functions file. It also allows modularity if you ever want to use your theme elsewhere.

    If you plan to expand any further beyond a few snippets, upgrade to a child theme, but if your site is basically where it will be for most of its life, let it ride.

  2. If you have 30 snippets you use when building every site then you might consider putting them in your own custom plugin. That way it’ll be more portable and you could comment things in and out in the dashboard.

    That said, if it’s just this one site and especially if you’re pretty sure no one else will ever work on it then your snippets plugin should be fine. (It’s hard to imagine the mere existence of a snippet manager would affect performance more than the actual snippets would.)

    All that said, I’d *still* recommend using a child theme as future proofing even if you never plan to touch it. It doesn’t hurt anything and some say it might be useful.

  3. Mostly, Code Snippets works fine. Some snippets, and it seems you’ve not needed one yet, need to execute before Code Snippets runs. Such snippets must be in functions.php of the child theme if they are to work, because this code executes earlier in the page build sequence.

    functions.php covers both cases, hence the general recommendation that that’s the way to go.

    I’d expect performance to be the same either way.

  4. Snippets are stored in database.

    Child theme is better choice. Your code belongs there. And it’s easier for future reuse.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer