A plugin or a snippet of code: how to add a feature to WordPress

Short answer: if the feature has screens, options or is complicated (forms, SEO, shop, bookings), use a well-maintained plugin. If it is a small, exact change (hiding a field, changing a text, adjusting a behaviour), a snippet of code can be lighter. What you should never do is paste code into the theme file and expect it to last.

The three routes

Ready-made plugin Code snippet Plugin of your own
When it fits A feature with screens, options or many parts. A small, precise change. Code you want to keep and reuse, and that must survive a change of theme.
Effort Install and configure. Copy, read, test. Write it, or ask someone who can.
Who maintains it The plugin’s author. You. It may stop working with a new version of PHP or WordPress. You, or whoever wrote it.
Main risk An abandoned plugin, or one that does a hundred things when you need one. A typing error can take the whole site down. The same, plus nobody who knows it a year from now.
Survives a theme change? Yes. Only if it is not in the theme files. Yes.

How to decide, step by step

1 Describe the feature in one sentence and look for a plugin that does exactly that. Before installing, look at the date of the last update, the compatibility and the answers in the forum: installing WordPress plugins.
2 Be wary of the plugin that does a hundred things when you only need one. Every plugin weighs on every visit; a three-line snippet may cost less.
3 Choose where the snippet goes. Not in the theme’s file editor: an update wipes it, and a mistake takes the site down. Use a snippets plugin (which lets you switch a snippet off without touching files), a small plugin of your own, or a child theme: child theme or direct editing.
4 Take a copy and test first on a test site, or at least with a recent copy at hand: a test site.
5 Write a note saying what the snippet does, where it came from and the date you added it. A year from now nobody remembers.
Copied code runs with all of your site’s rights. Do not paste what you have not understood, or from places you do not know. And one stray comma in a PHP file is enough to give the “critical error”. If that happens and you cannot get into the dashboard, see disabling plugins even when you cannot get in and common WordPress errors.
Code written for one PHP version can fail on another. Before changing version, see which PHP version your site should use. And keep in mind that custom code is yours: support does not write it or repair it, as explained in how far our support goes.

About to change something on your WordPress and want to do it safely? Start with a backup.

Open a support ticket

SEE ALSO

Installing WordPress plugins: where, which ones, and how many

Disabling plugins, including when you cannot get in

A child theme or editing the theme directly

How far our support goes

RECOMMENDED PRODUCT

WordPress hosting

One-click install, updates handled, and speed that holds up. from $6.60/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?