WordPress · Plugins · PHP

When should you build a custom WordPress plugin?

When a custom WordPress plugin beats an off-the-shelf one, when a code snippet is enough, and how I build plugins that stay safe, small and easy to change.

Mohit Goyal 5 min read
When should you build a custom WordPress plugin?

Build a custom WordPress plugin when your rule is specific enough that bending a general plugin would take longer than writing a small one, or when the logic is so important to the business that it must survive any theme change. Use an existing plugin when it fits, and a short code snippet when the change is one line. I have written plugins for client delivery rules and lead verification, and published two on WordPress.org, including HTTP Security Header with more than 1,000 active installs.

How do you decide between an existing plugin, a snippet and a custom plugin?

SituationBest choiceWhy
A well-maintained plugin does exactly what you needExisting pluginSomeone else maintains and tests it
A one-line change to WordPress behaviourA small snippet or hookA plugin would be overhead
Your rule is specific and the nearest plugin needs workaroundsCustom pluginSmaller and easier to change than a bent general plugin
Logic the business depends on, such as leads or checkout rulesCustom plugin, separate from the themeSurvives redesigns and theme updates
A gap in a builder or plugin many people useCustom plugin, maybe publishedOthers have the same gap

When is a custom plugin the right call?

When your rules are specific

Whitfield Service Station sells food from three brands on one forecourt in Dover. Delivery had to stop at a sensible radius, and fees had to reflect distance. I wrote my own Delivery Restriction Checker plugin rather than configuring a shipping extension. It geocodes the customer's address with the Google Maps API, hides delivery beyond 10 miles, charges a distance-based fee and falls back to pickup or dine-in.

The payoff came later. The owner decided to switch to a flat delivery fee, and because the rules lived in a small plugin I owned, it was a quick change rather than a fight with someone else's settings screen.

When the logic must survive a redesign

PropAlert follows up on every enquiry by phone, so a fake number is worth nothing. I connected the team's existing WPForms setup to an OTP (one-time code) API through custom plugins, so every enquiry arrives with a verified phone number. The verification lives in plugins, not in the theme, so a theme change later does not touch the lead flow. The team kept the form tool they knew.

When a popular tool has a gap

Bricks Builder has a conditions system but no way to vary content by visitor location. Agencies were duplicating pages per country. I wrote Geo Targeting for Bricks Builder, which adds a country condition to any Bricks element. The lookup runs on the server through IPinfo Lite, so there is no flicker of the wrong content, and nothing about the visitor is stored. It is published on WordPress.org.

When the safe way is too hard for most owners

Adding security headers normally means editing .htaccess or server config, which site owners are rightly afraid to touch. My HTTP Security Header plugin lets anyone switch the important headers on from a settings screen. It now reports more than 1,000 active installs and a 5 out of 5 rating on WordPress.org. The details are in how to add HTTP security headers to WordPress.

When is a snippet enough?

Not every change needs a plugin. For Taxocity, every Bricks form submission is written to a Google Sheet that the firm's CRM reads from. That is a PHP hook on form submission, not a product. I evaluated a direct CRM webhook and a form migration first, and settled on the sheet because the team already worked in Google Sheets.

My rough rule: if it has no settings, touches one site and fits on a screen, a hook in a site-specific plugin or a code snippet tool is fine. Once it has settings, rules or more than one site, make it a proper plugin.

How do you build a plugin that stays safe and easy to change?

  1. 1

    Use WordPress's own APIs

    The settings API for options, hooks for behaviour, and the REST API for anything a frontend calls. The plugin behaves like core and is easy to audit.

  2. 2

    Validate everything

    Check values before saving them and check input at every form or request.

  3. 3

    Fail safe

    If a setting is wrong, fall back to a working value instead of breaking the site or locking out the admin.

  4. 4

    Store as little as possible

    Geo Targeting writes nothing to the database, so it has no personal data to protect.

  5. 5

    Load only where needed

    Scripts and styles belong on the pages that use them, not on every request.

  6. 6

    Document the edits people will make

    Settings, rule changes and what to do when something looks wrong.

The fallback point is the one I care about most. In HTTP Security Header, a bad Content-Security-Policy or a mistyped frame option cannot lock an admin out of their own site, because the plugin falls back to a working value. Maintaining it has taught me that safe defaults matter more than coverage.

What about plugin bloat?

Custom plugins can reduce bloat. One focused plugin often replaces two general ones plus the workarounds glued between them. I still cap client sites at a dozen active plugins, and I remove anything unused. The Raasa launch page had a leftover WooCommerce install from a theme demo, which only added weight and attack surface.

For stricter environments, plugins can be managed like code. On the Janssen Neuroscience site, every theme and plugin was pinned to a version and installed through Composer, so updates were reviewed changes rather than clicks in the admin.

What does a custom plugin project look like?

Usually small. Write down the rule in plain words, the edge cases and who changes the settings. The free PRD Generator turns a short description into user stories with acceptance criteria, which is a good starting brief for a plugin.

I build these through my custom WordPress plugins service, for single sites and for WordPress.org. Send me the rule you are fighting with and I will tell you whether it needs a plugin, a snippet or a setting you have not found yet.

Frequently asked

Is a custom plugin better than a theme's functions.php?+

For anything that matters to the business, yes. Code in functions.php disappears when the theme changes. A plugin keeps working through redesigns and theme updates.

Will a custom plugin slow my site down?+

A focused plugin usually loads less than a general one, because it only does your job. Speed problems come from plugins that load scripts on every page whether they are needed or not.

Who maintains a custom plugin after launch?+

Whoever built it, or any WordPress developer with the code. Keep the code in version control and documented. I maintain my public plugins and the client plugins I write.

Can a custom plugin be published on WordPress.org?+

Yes, if it is general enough to help others. Two of mine are published there, HTTP Security Header and Geo Targeting for Bricks Builder. Client-specific plugins usually stay private.

How do I know whether a plugin already exists for my need?+

Search WordPress.org and the ecosystem of your builder or store plugin first, and read the reviews and update history. If the nearest match needs workarounds for your core rule, that is the sign to build.

Mohit Goyal

Written by Mohit Goyal

Senior Web Developer in Gurugram, India. 100+ fast, SEO-friendly sites shipped in 4+ years with Next.js, React and WordPress, including the procol.ai rebuild. Send me your next project.

Keep reading

Let's build

Have a site that needs to be fast, rank and convert?

Open to Work. Usually replies within a day.