Skip to content
Snippets Library

How to Safely Add Code Snippets to WordPress

Every snippet in this library tells you where to add it. This page explains what those three locations actually mean, and the habits that keep a copy-pasted snippet from taking down your site.

The Three Places a Snippet Can Go

Every snippet in this library specifies one of three locations. They’re not interchangeable — each one has a different lifecycle, a different blast radius when something goes wrong, and a different reason it’s the right (or wrong) fit for a given snippet.

1. Your child theme's functions.php

functions.php runs on every page load for your theme, and edits there are easy to make and easy to revert — delete the code, save, done. The catch is that it’s tied to your theme: if you switch themes, or if your child theme setup isn’t actually correct, the snippet stops running with no warning. It’s the right home for snippets that are genuinely about theme behavior or presentation, and that you’d expect to change or remove alongside the theme itself.

2. A small custom plugin

A plugin (even a single-file one with just a plugin header comment at the top) keeps running regardless of which theme is active. That matters for anything that’s really an application-level change — security policy, data handling, WooCommerce behavior — rather than a visual one. It’s slightly more setup than pasting into functions.php, but it means a future theme change can’t silently undo a security fix you made months ago.

3. A snippet manager plugin

Plugins like WPCode or Code Snippets give every snippet its own on/off toggle, a description field, and a record of when it was added — all without creating a new file anywhere. That makes them the safest option when you want to be able to instantly disable a change without editing a file, especially for anything you’re not 100% sure about yet, or that you might need to turn off quickly if it conflicts with another plugin later.

Before You Add Any Snippet

  • Back up your site first. A full backup — files and database — takes a few minutes and means any mistake is a five-minute rollback instead of a support ticket.
  • Test on staging if you have it. Most hosts offer a one-click staging copy. A snippet that behaves unexpectedly on staging costs you nothing; the same surprise on a live site costs you traffic, orders, or trust.
  • Add one snippet at a time. If you paste in three changes at once and something breaks, you’re debugging three changes instead of one. Add it, check the site, then move to the next.
  • Read the warnings section. Every snippet page in this library lists specific caveats — compatibility notes, edge cases, things that only apply to certain setups. They exist because they’re relevant, not as legal boilerplate.

If Something Breaks

A white screen or a fatal error after adding a snippet almost always means exactly one thing: the code you just added. If it’s in a snippet manager, deactivate that one snippet from its plugin list — the site should recover instantly. If it’s in functions.php and the site is unreachable through wp-admin, connect via FTP/SFTP or your host’s file manager, open functions.php, and remove the block you added. If it’s in a custom plugin, the fastest fix is renaming that plugin’s folder from the file manager — WordPress deactivates any plugin it can’t find on the next page load, and your site comes back immediately. This is exactly why testing one change at a time matters: you’ll always know precisely which block to remove.

We use cookies

We use essential cookies to run this site, and optional cookies to understand usage and remember your preferences. Read our Cookie Policy to learn more.