WP-CLI
Snipfire adds wp snipfire commands to WP-CLI. Run wp help snipfire <command> for the built-in help.
Commands marked Pro need Snipfire Pro; git needs the Agency plan (or its trial).
Unlike the editor, WP-CLI isn't limited by team access: anyone who can run WP-CLI on the server can do everything.
Snippets
list
wp snipfire list [--type=<php|css|js|html>] [--status=<active|inactive>] [--folder=<folder>]
[--hook=<hook>] [--fields=<fields>] [--format=<format>]
| Option | Meaning |
|---|---|
--type, --status |
Only this type, or only active or inactive snippets |
--folder |
Only snippets in this folder (not its subfolders) |
--hook |
Only snippets at this location, for example wp_head |
--fields |
Columns to show, comma-separated: id, title, folder, type, status, run, hook, priority, position, conditions, error |
--format |
table (default), json, csv, yaml, ids, count |
wp snipfire list --type=php --status=active
wp snipfire list --folder=Library --fields=id,title,status
wp snipfire list --format=count
get
wp snipfire get <id> [--field=<field>]
wp snipfire get 12 --field=code > snippet.php
create
wp snipfire create --title=<title> [--type=<type>] [--code=<code>] [--file=<file>]
[--hook=<hook>] [--position=<n>] [--priority=<n>] [--run=<auto|shortcode|manual>] [--shortcode=<tag>]
[--lang=<css|scss|less>] [--mode=<live|test>] [--consent=<category>]
[--folder=<folder>] [--description=<text>] [--tags=<tags>]
[--load-as=<inline|file>] [--conditions=<json>] [--active] [--porcelain]
| Option | Meaning |
|---|---|
--type |
php (default), css, js or html |
--code / --file |
The code, or a file to read it from (- for stdin) |
--hook |
Where it runs: a location key from Location keys, or any action name for PHP/HTML |
--position |
Which paragraph, or which post in the list, for the HTML locations that take a number. Default 1 |
--priority |
Default 10 |
--run |
auto (default), shortcode or manual |
--shortcode |
Custom shortcode tag |
--lang |
CSS snippets: css, scss or less (Pro to compile) |
--mode |
live, or test for testing mode (Pro) |
--consent |
JS/HTML: statistics, marketing, preferences, functional, or "" for none (Pro) |
--folder |
For example "WooCommerce/Checkout" |
--description, --tags |
Notes; comma-separated tags |
--load-as |
CSS/JS: inline or file |
--conditions |
Conditions as JSON; see Conditions as JSON |
--active |
Switch it on after saving (after the checks and the test load) |
--porcelain |
Print only the new ID |
wp snipfire create --title="Disable XML-RPC" --code="add_filter( 'xmlrpc_enabled', '__return_false' );" --active
cat tracking.html | wp snipfire create --title="GA4" --type=html --hook=wp_head --file=- --porcelain
wp snipfire create --title="Newsletter box" --type=html --hook=the_content:paragraph_after --position=3 --file=box.html
update
wp snipfire update <id> [same options as create] [--active] [--inactive]
Only the options you give change.
wp snipfire update 12 --file=snippet.php
wp snipfire update 12 --mode=live
enable / disable / delete
wp snipfire enable <id>... [--skip-test]
wp snipfire disable <id>...
wp snipfire delete <id>...
enable checks each snippet and test-loads the site first, like the editor. --skip-test skips the test load (the checks still run).
run
wp snipfire run <id>
Runs a PHP or HTML snippet once and prints its output. Conditions are ignored.
History
wp snipfire revisions <id> [--format=<table|json|csv|yaml>]
wp snipfire restore <id> <rev>
restore checks and test-loads the restored version like any save, and keeps the current version in the history.
Export and import
wp snipfire export [<id>...] [--file=<file>]
wp snipfire import <file> [--keep-status]
Imported snippets arrive switched off unless you add --keep-status.
import-from
wp snipfire import-from [<source>] [--ids=<ids>] [--dry-run] [--update] [--switch] [--format=<table|json>]
Without a source, lists the plugins Snipfire found snippets for. Sources: wpcode, code-snippets, fluent-snippets, hfcm, custom-css-js, post-snippets, woody, customizer-css, wpcodebox.
| Option | Meaning |
|---|---|
--ids |
Only these snippets (the other plugin's IDs, comma-separated) |
--dry-run |
Show what would be imported and how, without importing |
--update |
Re-import snippets imported before (refreshes code and settings) |
--switch |
After importing, switch the snippets off in the other plugin and on in Snipfire |
See Switching from another plugin.
library
wp snipfire library [list|packs|show|install|update] [<slug>...] [--pack=<pack>] [--activate] [--all] [--format=<format>]
The snippet library.
| Action | What it does |
|---|---|
list (default) |
Every library snippet with its state on this site (new, current, changed, update), its snippet ID and status, and what it needs. --pack lists one pack |
packs |
The packs and how many snippets each has |
show <slug> |
One snippet: title, description, notes and code |
install <slug>... |
Install snippets, switched off, in the Library folder. --pack installs a whole pack. --activate switches them on after the checks and one test load; snippets that need your details or a missing plugin stay off |
update <slug>... |
Update installed snippets to the library's version, keeping the settings you changed. --all updates every snippet with an update |
--format for list and packs: table (default), json, csv, yaml, count.
wp snipfire library --pack=harden
wp snipfire library install --pack=clean-head --activate
wp snipfire library install disable-xmlrpc year-shortcode
wp snipfire library update --all
shortcodes
wp snipfire shortcodes [--rewrite] [--dry-run] [--state=<state>] [--format=<format>]
Lists where snippet shortcodes are used in posts, templates and widgets: Snipfire's own (and whether they print anything) and ones left over from WPCode, Code Snippets, FluentSnippets, Header Footer Code Manager, Woody Code Snippets and Post Snippets.
| Option | Meaning |
|---|---|
--state |
Only this state: ok, rewrite, kept, other, missing or inactive |
--rewrite |
Rewrite old shortcodes of switched-over snippets to [snipfire id="…"]. Posts get a revision first |
--dry-run |
With --rewrite: only say what would change |
--format |
table (default), json, csv, yaml, count |
See Find where shortcodes are used.
files
wp snipfire files [<file>] [--set=<text>]
The site files Snipfire serves. Without a file name, lists them with their address and whether a real file on the server takes precedence. File names: robots, ads, app-ads, llms, security.
wp snipfire files llms # show llms.txt
wp snipfire files llms --set=- < llms.txt # new contents from standard input
wp snipfire files ads --set="" # empty it: ads.txt is switched off
Safe mode and storage
wp snipfire safe-mode [status|new-key]
wp snipfire info
info shows where Snipfire stores snippets and whether it can write there.
To run any command with all snippets stopped, define the safe mode constant for that one command:
wp --exec='define( "SNIPFIRE_SAFE_MODE", true );' snipfire list
access Pro
wp snipfire access [list|set|check] [<role-or-user>] [<level>]
wp snipfire access # each role's level
wp snipfire access set editor design # none, view, design or full
wp snipfire access check jane # a user's level (login, email or ID)
design is the CSS, JS and HTML level. See Team access.
consent Pro
wp snipfire consent [status|fallback|gpc] [<value>]
wp snipfire consent # the consent tool found, the settings, and how many snippets wait
wp snipfire consent fallback allow # without a consent tool: block (the default) or allow
wp snipfire consent gpc off # Global Privacy Control: on (the default) or off
See Cookie consent.
preview Pro
wp snipfire preview [status|new-key]
Shows the testing mode preview link, or makes a new one (old links stop working).
log Pro
wp snipfire log [--snippet=<id>] [--user=<user>] [--action=<action>] [--limit=<n>] [--format=<table|json|csv|yaml>]
Actions: created, updated, enabled, disabled, auto_disabled, deleted, restored, imported, switched_over, moved, settings, access, git_pulled, git_sync. Default limit 50. See Activity log.
git Pro
Needs the Agency plan or its trial.
wp snipfire git setup [--provider=<github|gitlab>] [--repo=<repo>] [--branch=<branch>]
[--root=<folder>] [--scope=<folder>] [--token=<token>] [--remove-token] [--api=<url>]
[--schedule=<off|hourly|twicedaily|daily>] [--check]
wp snipfire git check
wp snipfire git sync [--format=<text|json>]
wp snipfire git status [--format=<text|json>]
wp snipfire git resolve <uid>... --keep=<site|git> [--format=<text|json>]
wp snipfire git reset
setup option |
Meaning |
|---|---|
--provider |
github or gitlab |
--repo |
owner/name, or the repository's address |
--branch |
Default main |
--root |
Folder in the repository. Default snipfire; "" for the top |
--scope |
Only sync this Snipfire folder (and subfolders); "" for all |
--token / --remove-token |
Save (encrypted) or remove the access token. Or define SNIPFIRE_GIT_TOKEN |
--api |
API address for GitHub Enterprise Server or self-managed GitLab |
--schedule |
Automatic sync |
--check |
Test the connection afterwards |
setup only changes the options you give. resolve all --keep=site settles every conflict. See Git sync.
Something unclear or missing? Tell us