Skip to content

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.

Terminal window
# 1. Download existing snippets from WordPress
lps snippet pull
# 2. Edit locally, commit to Git
git add snippets/ && git commit -m "feat: update price formatter snippet"
# 3. Deploy back to WordPress
lps snippet push

Download all snippets from WordPress and write them as .php files.

Terminal window
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:

Terminal window
lps snippet pull ./wp-snippets --dry-run

Upload .php files from a local directory to WordPress.

  • If the sidecar .json contains an id, 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.
Terminal window
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:

Terminal window
lps snippet push ./wp-snippets

Print all snippets currently on WordPress.

Terminal window
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: ✗

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).

Terminal window
lps snippet publish [path]
Argument Default Description
path ./snippets (or loopress.json’s snippetsDir) Local directory to read snippet files from

Example:

Terminal window
lps snippet publish
lps snippet publish ./wp-snippets

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.json

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"]
}
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).