Snippets
The snippet command group lets you version-control PHP snippets as plain files in Git. Each snippet is stored as a code file alongside a .json sidecar in a local directory that you commit like any other code.
Works with either WPCode or the Code Snippets plugin. The Loopress WordPress plugin detects whichever one is active on the site, so the CLI commands are the same either way.
Typical workflow
Section titled “Typical workflow”# 1. Download existing snippets from WordPresslps snippet pull
# 2. Edit locally, commit to Gitgit add snippets/ && git commit -m "feat: update price formatter snippet"
# 3. Deploy back to WordPresslps snippet pushCommands
Section titled “Commands”lps snippet pull
Section titled “lps snippet pull”Download all snippets from WordPress and write them as .php files.
lps snippet pull [path]| Argument | Default | Description |
|---|---|---|
path |
./snippets |
Local directory where snippets are written |
| Flag | Description |
|---|---|
--dry-run / -d |
Show what would be written without touching the filesystem |
Example:
lps snippet pull ./wp-snippets --dry-runlps snippet push
Section titled “lps snippet push”Upload .php files from a local directory to WordPress.
- If the sidecar
.jsoncontains anid, that snippet is updated by ID. - If that id doesn’t exist on the target site (e.g. a fresh WordPress install), a new snippet is created instead and the local sidecar is updated with the assigned id.
- Otherwise, a new snippet is created.
lps snippet push [path]| Argument | Default | Description |
|---|---|---|
path |
./snippets |
Local directory to read .php files from |
| Flag | Description |
|---|---|
--dry-run / -d |
Show what would be pushed without making any changes |
Example:
lps snippet push ./wp-snippetslps snippet list
Section titled “lps snippet list”Print all snippets currently on WordPress.
lps snippet list| Flag | Description |
|---|---|
--json / -j |
Output raw JSON instead of formatted text |
Example output:
Found 3 snippets:
1. price-formatter Active: ✓ Tags: cli-import Description: Formats WooCommerce prices
2. redirect-homepage Active: ✗lps snippet publish
Section titled “lps snippet publish”Publish local snippet files to your Loopress account so they can be deployed to other projects. This does not touch any WordPress site, it uploads to Loopress only.
Requires lps login first, and the current project must be linked to your Loopress account (lps project push).
lps snippet publish [path]| Argument | Default | Description |
|---|---|---|
path |
./snippets (or loopress.json’s snippetsDir) |
Local directory to read snippet files from |
Example:
lps snippet publishlps snippet publish ./wp-snippetsFile format
Section titled “File format”Each snippet is stored as two files in the snippets directory: a code file and a .json sidecar that holds the metadata. Files are named {id}-{slug}.{ext}, where {slug} is the snippet name lowercased and slugified.
snippets/ 42-price-formatter.php 42-price-formatter.json 17-redirect-homepage.php 17-redirect-homepage.json 11-custom-login-logo.css 11-custom-login-logo.jsonSidecar files
Section titled “Sidecar files”lps snippet pull writes a .json sidecar next to each snippet file. The sidecar holds the metadata that lps snippet push uses to identify and configure the snippet on WordPress.
{ "id": 42, "name": "Price Formatter", "type": "php", "active": true, "description": "Formats WooCommerce prices", "tags": ["woocommerce", "formatting"]}Supported fields
Section titled “Supported fields”| Field | Description |
|---|---|
id |
WordPress snippet ID. Used by push to update the correct snippet. |
name |
Snippet title in WordPress. Takes precedence over the filename. |
description |
Optional description shown in the WordPress admin. |
type |
Snippet type: php, css, js, html, or text. |
tags |
Array of tag strings. |
active |
Whether the snippet is active (true / false). |