When Should You Use Code Snippets vs Plugins?

Last Updated on September 21, 2022 by 23 Comments

When Should You Use Code Snippets vs Plugins?
Blog / Tips & Tricks / When Should You Use Code Snippets vs Plugins?

WordPress Facebook groups are awesome. Just search for “WordPress,” “Elegant Themes,” or “Divi” and the groups that pop up will astound you. One of the biggest questions from beginner users all the way to advanced ones seems to boil down to What’s the best plugin to do X, and every time, there are dozens of responses with suggestions. And that’s great.

But the issue that this question skips over is how can I do X with WordPress, which is not a plugin question. It is a code question. All WordPress plugins are just packaged bits of code that you plug in (hence the name) to the main WP backend. Some plugins like the Divi Builder add major functionality that expand the bounds of what’s possible with the core. But many are minimal snippets of PHP that accomplish a single task that users could implement on their own.

So I guess the question I need to answer then is, when should you use code snippets vs plugins? So here are some things to consider.

How Much is Your Time Worth?

A big reason folks come to WordPress over other CMS platforms or blogging software is because of the rich plugin ecosphere. A plugin exists for pretty much every situation that a WP user could potentially come across, from SEO to page building to accepting payments to making child themes and so on. And with just a few mouse clicks and tap-tap-taps on the keyboard, voila…problem solved/new feature added.

When your time is limited (or your client’s budget is), you have to cut a few corners or make your decisions based on that. If you have a same-day deadline to get a fix on a major site and you can do that with a plugin vs a code snippet in functions.php, you’re going to go for the plugin every time. We’ve all done that.

Time really is money, and plugins are quick. So a lot of designers and developers have a stable of standard plugins they install that helps them keep clients happy and the turnaround for new sites and jobs far quicker than if they were hand-coding things for every single client.

You need to gauge the ROI on your work, just as with everything else.

Consider the Long Term Effects

As quick and easy as installing a plugin can be, you also have to consider the long-term life of your site. What might look like a panacea right now might turn into a headache that might later turn into a migraine.

WordPress is always changing. If the plugin code doesn’t, too, they can easily become obsolete. If the developers abandon a project or are slow to update, you could lose some basic functionality. The scary part is that you might have no idea as to when you might get it back. (And that can cost oodles of revenue and profits.)

Most importantly, if you use a plugin to solve a problem that is just as easily solved with a code snippet, you avoid potential issues with the plugin.

For instance, I’ve seen people use a plugin to remove the sidebar on posts and pages. In effect, all that plugin does is edit your single.php file. You can open it up, remove a single line to accomplish the same thing.

< ?php get_sidebar(); ?>

Isn’t that better than keeping a plugin installed for years?

Do You Trust The Developer?

There are millions of plugins available for free when you hit the repo. And I would trust a minuscule fraction of them on any site I or a client runs.

Why?

Because I don’t know who in the world put that thing together. I don’t know how good they are at coding. I don’t know how efficient they are with updates or how well their code interacts with the WordPress database. Maybe their code makes twice the number of queries it should for any given action. I don’t know. But I know what my code will do when I write it.

You also have the issue that the developers might just stop supporting the plugin. As it ages, it may become incompatible and force you to find another solution to your problem. That is time which equates to lost revenue. And lost productivity because you’re re-solving a problem that already had a solution.

Using your own code snippets helps avoid this pitfall. You still have to maintain the code additions. (Which is specifically why you should be using child themes.) You will know what, where, and why changes were made. You’d know how to update the code snippets you added, and most importantly, you would be in control of the whole process yourself.

Plus, if you’re directly editing the PHP files that come with WordPress, you’re likely adjusting base functionality that won’t be changing much, while plugin APIs and interactions will. Think about the havoc that might be wreaked if the get_sidebar() function gets changed even a little and that plugin doesn’t?

Trusted Developers are Amazing, Though

When you do find a plugin developer whose work you trust, they can save you a lot of headache. For instance, I often use a plugin that installs and activates child themes in just a few clicks. I can then delete the plugin from my site.

That is a lot quicker than installing a child theme manually. I know it doesn’t leave behind weird stuff, so I trust it. These situations are why plugins exist. They are designed to make your life and website better, not replace your expertise.

I had a professor in graduate school tell me once that “you have to know the rules before you’re allowed to break them.” You can look at plugins the same way. They’re for time-saving, not job-doing.

Do You Have Access to WordPress Files?

A major factor in whether or not to use code snippets vs plugins has to do with how much access to the file system you have. To add code snippets into the WordPress core files, you need FTP access (or at the very least cPanel credentials). Some companies and clients don’t give that out. In some cases, clients may not know how.

If you are locked out of the files, you really have no choice but to use plugins.

And if they’re keeping things on lockdown, voluntarily or not, plugins will be how they generally want to interact with the software. Using plugins makes problem solving easier. (Stop me if you’ve heard this one: “start by disabling all your plugins…”)

Changing the core files with code snippets or custom code isn’t something a lot of end users want to deal with. I have personally been told by clients that under no circumstances did they want custom code, even CSS, and to do everything in the theme options and customizer. That was fun.

How Much Code Do You Know/Want to Know?

For many people, a big hindrance from editing the core PHP files is simply because they don’t know PHP or JavaScript.

I mean, I couldn’t edit a page written in Spanish despite being okay at words in English. Folks who don’t know the languages can’t change what the code does.

But here’s my question to you: how much do you want/need to know?

Digging into the WordPress core files is the single best way to learn the system I know of. You can read tutorials and documentation all day long, but there’s still no replacement for getting in there and editing functions.php yourself.

If you have no desire or your career trajectory isn’t going to be helped by learning the code you’d need to replace plugins, then by all means, plug it in, plug it in. There’s no reason not to.

But if your future relies in any way on understanding the inner workings of WordPress, trying to implement solutions without plugins is a great way to ease into unfamiliar territory.

For example, I learned how to read and edit single.php by needing to move where the title appears on the page. Plugins can do that easily. But it turns out, so can HTML (with a basic PHP function baked in).

<h1 class="entry-title">< ?php the_title(); /></h1>

Doing something as simple as rearranging that one line of code in single.php can be the gateway to being able to adjust code snippets all over the WP core in lieu of plugins. And that snowballs into more confidence and ability, which directly relates to knowing when it’s better to use a plugin than code it yourself.

A Good Rule of Thumb

I follow a life-changing piece of advice I learned from a podcast: if a task takes 1 minute or less, do it immediately instead of putting it off. You can kind of adapt that to WordPress code snippets vs plugins, too: if writing a code snippet takes as much or less time than installing and configuring a plugin, just write the code.

Of course, you have to weigh that decision based on how much code you know and intend to learn overall. In the end, that approach has made me far more knowledgable of WordPress, PHP, and the entire plugin ecosystem. I think the same thing will happen to you, too.

So next time you hit the plugin repo, pause for a second. Ask yourself, “could I do this with code?” And if the answer is “yes,” follow that up with a “but is it worth it?”

Then you’ll have your answer to the age old “code snippets vs plugins” debate.

What makes you decide whether to use code snippets vs plugins?

Article thumbnail by hanss / shutterstock.com

Divi

Want To Build Better WordPress Websites? Start Here! 👇

Take the first step towards a better website.

Get Started
Divi
Premade Layouts

Check Out These Related Posts

Splice Video Editor: An Overview and Review

Splice Video Editor: An Overview and Review

Updated on March 10, 2023 in Tips & Tricks

Video is a valuable form of content for social media. Unfortunately, creating quality videos is usually a long process that involves moving mobile footage to a desktop app for editing. However, mobile editing is on the rise. Apps such as Splice Video Editor make it possible to efficiently create...

View Full Post
How to Use Font Awesome On Your WordPress Website

How to Use Font Awesome On Your WordPress Website

Updated on September 16, 2022 in Tips & Tricks

When given the choice between using a vector icon or a static image, it’s a good idea to go with the vector. They’re small and fast to load, and they can scale to any size without a loss of resolution. Font Awesome is a superb library of vector icons that you can use on your websites,...

View Full Post

23 Comments

  1. Well, i always prefer plugins as it’s much easier and faster

    • Except it’s not faster in the long run if you’re looking at site-load speed, for example.

      And in my experience, it takes just as much time to search for a plugin as it does to search for a snippet of code. And honestly, inserting that snippet is usually faster for me 😉

  2. I’d add to the whole thing that all of the screwing with php and JS should be done in a testing/staging environment as for a wrong bit of code the site crashes immediately, this is something will happen FOR SURE…

  3. Thanks BJ Beeton 🙂 Really useful postindeed!

    I gather you are referring the to the’ The One Click Child Theme Plugin ‘ can you confirm?

    Your post have given me an excitement to learn about basic html coding in wordpress, can you signpost me to a recommended site or tutorials?

    With thanks
    Mark

  4. Nice article.

    Would a company like Divi Space be a reliable source to purchase plugins? I’m creating a site for a client that uses Extra Module Mate. I was wondering could using a plugin like this come back to haunt me later on.

    Thanks for your time.

  5. Please – what is the child theme plugin you use?

    • This is one of the 1st thing to learn… there is no need at all for a plugin to make a child theme, just scout WP knowledge base…

  6. Great article! Good reflections!

  7. It pains me to use any plugins at all always has , especially those social ones . I’ve so far hard coded share icons and an author box in to single post pages , where as literally 99 percent of people are using plugins just think it’s silly especially when they make the page load way slower . I’m currently trying to get a click to tweet content effect without using the tweet plugin too . Where it auto fills the tweet with the text highlighted .

    • I am that way, too. I recently did an audit of a 5 year old site I ran, and I was flabbergasted at how many plugins I still had on there.

      I would be interested to see how the Click to Tweet function turns out!

  8. Many thanks

  9. Great topic, coverage & advice on WordPress. Many thanks.

  10. THat is great info, BUT, if ANYTHING is done in code, its done in CHILD theme. A MUST. Or there will be a lot of problems.
    AND also one thing not mentioned. COMMENT EVERYTHING in code what are you doing, cause when you get back to it after year to still know what part of code is changed. Sometimes the changes in code are small.

    And for end, how to best keep track of all the changes in code except comments. Maybe on dashboard, like memos. Just to keep track and for future developers that will be working on page.

    • Very valuable postscript to the article – thanks

      • Totally agree. Excellent points. Especially about the comments. If you know how to comment with code, it’s only going to make your life (and the lives of people after you), unfathomably easier.

  11. Great article. Thanks!!

  12. Great article! I don’t know how to code but i learned to google the sh… out of it. So for example i made a lot of changes to the checkout and my account page without a plugin. Took me forever but is lighter on the code and made me proud too.?

    • You and me both. I think Stack Overflow is as much responsible for my transition from teaching to web dev as anything else, haha 🙂

  13. I’ve just started building websites. This is extremely helpful. Thank you!!!

    • Good luck with it, Janet! I am super happy it was helpful. 😀

  14. B.J. Keeton, you are great! This is a very important subject, and your post is just precious! Thank you for your time.

    • D’awwwwww *blush* Thank you! I do hope it helps. 🙂

Leave A Reply

Comments are reviewed and must adhere to our comments policy.

Get Started With Divi