Add code snippets safely

Some pages in these docs include PHP snippets for things the settings can’t do. This page shows how to add them safely. You don’t need to be a developer.

Use a snippets plugin

The easiest and safest way is a free snippets plugin, such as WPCode or Code Snippets:

  1. Install and activate the plugin.
  2. Add a new PHP snippet and give it a name you’ll recognise, for example “Refer a Friend – stack rewards”.
  3. Paste the code from the docs. Leave out the opening <?php line if the snippet plugin adds its own.
  4. Set it to run everywhere, unless the docs page says otherwise.
  5. Save and activate it.

Snippet plugins catch most errors and turn the snippet off instead of taking your site down. You can also turn a snippet off at any time without editing files.

Or use a child theme

If you prefer files, add the snippet to the end of your child theme’s functions.php. Don’t add it to the parent theme. Theme updates replace the parent theme’s files and remove your code.

Before you add a snippet

  • Test on a staging site first, if your host offers one.
  • Add one snippet at a time and check your store after each one.
  • Don’t add the same snippet twice. Two copies of a function with the same name cause a fatal error.
  • Change only the values the page tells you to, such as category slugs, amounts or messages.
  • Check the version. Each snippet says which plugin version it was checked with.

If something goes wrong

  • With a snippets plugin, turn the snippet off.
  • If you can’t reach the admin, connect with FTP or your host’s file manager. Remove the snippet from functions.php, or rename the snippets plugin’s folder in wp-content/plugins.
  • WordPress may email you a link to recovery mode. Use it to turn the snippet off.

If a snippet from these docs doesn’t work for you, contact support and say which page it’s from.

Related

Browse our plugins

Lightweight WooCommerce plugins built for speed. No bloat, no frameworks -- just clean code that works.

View all plugins
Stay in the loop

Get notified when we launch new plugins. No spam, just product updates.