Sometimes you find (or write) a great little snippet of PHP code that makes WordPress do exactly what you want. But instead of pasting it into your theme’s functions.php file (where it will be lost upon a theme update), it’s often better to package it as a stand-alone plugin.
I’ve written before about using a functionality plugin (a single plugin where you collect multiple snippets). That’s still a great option if you like keeping everything in one place. But if you’d rather keep things separate — or you want to be able to toggle snippets on/off individually — turning a snippet into its own stand-alone plugin is the way to go.
Benefits of the stand-alone approach:
- It works no matter which theme you’re using.
- You can easily disable it without editing files.
- You won’t lose your changes during a theme update.
Think of it like wrapping your snippet up in its own little gift box. 🎁 Let’s get into it!
1. Create a New File
Open a plain text editor and create a new file. Name it something like: my-snippet-plugin.php and save it.
2. Add the Plugin Header
At the very top of the file, paste this standard WordPress plugin header (edit details as needed):
<?php /** * Plugin Name: My Snippet Plugin * Description: A simple stand-alone plugin to run a custom snippet. * Version: 1.0 * Author: Your Name * Author URI: https://yourwebsite.com */
3. Paste Your Snippet
Right below the header, add your snippet. For example:
// Disable product image zoom/lightbox
add_action( 'wp', function() {
remove_theme_support( 'wc-product-gallery-zoom' );
remove_theme_support( 'wc-product-gallery-lightbox' );
remove_theme_support( 'wc-product-gallery-slider' );
});
4. Package as a Zip for Easy Dashboard Upload
Almost done! Just a few quick steps and you’ll have your snippet running as a plugin — no messy FTP required.
- Save your file.
- Zip it up (right-click → “Compress” or “Send to Zip” on most computers, so you end up with my-snippet-plugin.zip.
- In WordPress, go to Plugins → Add New → Upload Plugin.
- Upload your zip, click Install Now, then Activate Plugin.
Whether you prefer one big functionality plugin (your “sack of toys”) or a collection of little stand-alone plugins (lots of neatly wrapped presents), the important part is keeping your snippets safe and portable. That way, you can use them year after year without losing a single bit of holiday magic.
Helpful Tip:
Keep a little folder on your computer (or even in GitHub) for all your snippet plugins. Over time, you’ll have your own personal WordPress toolbox, ready to use on any site
