Use a small custom WordPress plugin when the code is part of how the site works and you need to deploy, review, or disable it as a unit. Keep a code snippet when the change is small, local to one site, and easy to manage with the snippet tool you already use. Put presentation code that belongs to a particular theme in a child theme. The deciding factor is what the code belongs to, not how many lines it takes.
Decide what should own the code
A shortcode used in published pages, a few related editorial rules, or an integration with another plugin can make sense as a small custom plugin. Consider a support-link shortcode used throughout a site. You want those links to keep working when you change themes, and you may want to review changes to the shortcode alongside other site code. A regular plugin gives that feature a named entry on the Plugins screen and a file you can put under version control.
A snippet manager may already give you theme independence, per-snippet switches, and export. If you have one filter for one site and your team knows where to find it, a new plugin may just give you another thing to ship. On the other hand, if one feature needs three snippets enabled together, or if production keeps drifting away from staging because someone pasted an older version, package the feature as a plugin. A snippet can be five lines long and still have a surprisingly long handover meeting.
- Use a snippet: A local, independent tweak that you can find, export, and turn off without affecting related features.
- Use a regular custom plugin: Site behavior that should survive a theme switch and needs its own deployment or rollback, or related pieces of code that should travel together.
- Use a child theme: Template overrides and presentation changes that only make sense with the current theme.
Packaging code as a plugin does not make it faster or safer by itself. It changes how you manage the code. And while the plugin file is portable, any pages, settings, or other database records the feature depends on still need to be present on the destination site.
Move one existing snippet into a regular plugin
Work on staging first. Export or copy the current snippet, take a restorable backup, and note where the feature appears and when it runs. For a shortcode, find a page that uses it and check the public view before changing anything. For a filter or action, record the hook, priority, accepted arguments, and any conditions that control where it runs. A snippet manager’s “admin only” setting, for example, does not follow the PHP into a new file. Recreate that restriction deliberately if the code needs it.

- Create a folder and a main file. In a local working directory, create
site-support-linkand putsite-support-link.phpinside it. The plugin header tells WordPress what to list on the Plugins screen. - Move the behavior, not just the text. Preserve the shortcode tag or hook contract so existing content and integrations still work. If your snippet manager omits the opening
<?phptag, add it once at the beginning of the plugin file. Do not add a closing PHP tag to a PHP-only file. - Upload the plugin without activating it yet. Zip the
site-support-linkfolder, then use Plugins → Add New Plugin → Upload Plugin if your dashboard offers uploads. Otherwise, use your host’s approved deployment method to put the folder inwp-content/plugins. Menu labels and upload permissions vary by setup. - Switch owners on staging. Disable the original snippet, then activate the new plugin. Keep the old snippet saved but inactive until you’ve verified the replacement. Do not turn off the entire snippet manager if it runs other code.
Here is a complete example for a site that already uses [site_support_link] and has a public page at /support/. In a real migration, keep the original shortcode tag and intended output. This example returns the link rather than echoing it, so WordPress can put it where the shortcode appears.
<?php
/**
* Plugin Name: Site Support Link
* Description: Provides the site's support-link shortcode.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_shortcode( 'site_support_link', static function () {
return '' . esc_html( 'Contact support' ) . '';
} );
This plugin does not create a support page. Verify that the route exists, or use the correct path for your site. Keep the source in version control if your team uses it, or save a dated copy of the ZIP with a short note on what the plugin owns and how to roll it back.
Verify the handoff before moving to production
Open a page that already contains the shortcode in a logged-out window. Check the link text, click through to the destination, and compare the result with your baseline. If a page cache is serving old HTML, purge the affected URL through your usual cache controls and check again. A cached page is very good at confirming yesterday’s work.
On staging, test the rollback too: deactivate the new plugin, re-enable the saved snippet, and confirm that the feature works again. Then repeat the forward switch. If the migrated code writes data or changes settings, deactivation will not necessarily reverse those changes. The shortcode example only renders a link; it does not need a data rollback.
Troubleshoot the symptoms that matter
- The plugin isn’t listed. Check that the main file is a real
.phpfile and sits one folder down fromwp-content/plugins, not inside an extra layer of ZIP directories. Check that the file includes thePlugin Nameheader. If the upload menu is missing, check your permissions and hosting rules rather than treating it as a broken ZIP. - Activation fails or the site shows a critical error. Check the host’s PHP error log for the file and line. Look for a copied second opening tag, a missing dependency, or a named function still declared by the old snippet. If the dashboard is inaccessible, rename only the new regular plugin’s folder through your host’s file manager or SFTP to stop WordPress loading it at its recorded path. Once access returns, verify its status before restoring the folder name or reactivating anything.
- The shortcode appears as literal text. Check that the plugin is active on the site you’re viewing, that the tag matches exactly, and that the placement processes shortcodes. In the block editor, test in a Shortcode block rather than a Code block.
- The output is wrong or appears twice. Verify that the old snippet is off and check for other registrations. Two registrations of the same shortcode tag compete; the last one registered wins. Duplicate output is more likely when two callbacks on an action both print markup, or when the shortcode is present in two places. Rule out stale cached HTML before changing the code again.
Deploy the same package you verified on staging. Keep the rollback instructions with it: which plugin to deactivate, which snippet to re-enable, and which public page proves the switch worked. If someone else can follow that note without asking where the code lives, the plugin has earned its place.