Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

All docs

Your first snippet

In this guide you'll add a small PHP snippet, save it, and switch it on. It takes about five minutes.

The Getting started screen

On a site with no snippets yet, Snipfire → Snippets opens on Getting started: No snippets yet. Pick a way to start:

  • Import from another plugin, when Snipfire finds snippets in one: Import them. See Switching from another plugin.
  • Browse the snippet library: ready-made, tested snippets that install switched off. Open the library.
  • Add a header or footer script: a tracking code or verification tag. Open Header & Footer.
  • Start from scratch: New PHP snippet (or another type), as in the guide below.
  • Try a generator: fill in a form and get a working snippet. Open the generators.

Skip for now goes to the empty editor. Don't show this again stops the screen opening by itself; it's always under Getting started at the bottom of the sidebar. The screen only offers what your access level allows.

Open the editor

Go to Snipfire → Snippets (or Skip for now on Getting started). The editor has three parts:

  1. The sidebar on the left: your snippets and folders, + New, Search snippets…, and filters.
  2. The code editor in the middle, with the toolbar above it.
  3. The settings panel on the right: how, where and when the snippet runs.

Create a snippet

  1. Click + New and pick PHP.
  2. Give it a title in the box above the editor, for example Disable XML-RPC.
  3. Type this code:

    add_filter( 'xmlrpc_enabled', '__return_false' );
    

    While you type add_filter( ', Snipfire suggests WordPress hooks. Pick one and it writes the whole callback for you. More about autocomplete.

A PHP snippet can start with <?php or leave it off: both work.

Check the settings

In the settings panel:

  • How it runs: Automatically. (The other choices are As a shortcode and Only when I click Run, and with Snipfire Pro On a schedule: see Scheduled snippets.)
  • Where: Run immediately (like functions.php) is the default for PHP. That's right for add_filter() and add_action() calls.
  • Priority: leave it at 10. Lower numbers run first.
  • Conditions: leave empty. With no conditions, a snippet runs everywhere its location allows.

Everything in the panel is explained in How a snippet runs and Where snippets run.

Save and switch it on

  1. Turn on the Active switch in the toolbar.
  2. Click Save (or press Ctrl+S, Cmd+S on a Mac).

Before the snippet goes live, Snipfire checks the code for errors and test-loads your site with the snippet on. If everything is fine you'll see Saved and live. If the code has a problem, the snippet is saved but left switched off, and the problem is shown on its line so you can fix it. What Snipfire checks.

New snippets start switched off, so you can save work in progress without it running.

Switch it off again

Turn off Active and save, or tick it in the sidebar and click Off in the bulk actions bar. Switching a snippet off or on never changes its code.

Where next

Something unclear or missing? Tell us