Skip to content

Snippets

The snippets command group lets you version-control PHP snippets as plain files in Git. Each snippet is stored as a .php file in a local directory that you commit like any other code.

Supports the Code Snippets plugin (default) and WPCode.

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

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

Terminal window
lps snippets pull [path]
ArgumentDefaultDescription
path./snippetsLocal directory where snippets are written
FlagDescription
--dryRun / -dShow what would be written without touching the filesystem
--force / -fOverwrite existing local files
--plugin / -pTarget plugin: code-snippets (default) or wpcode

Example:

Terminal window
lps snippets pull ./wp-snippets --dryRun
lps snippets pull --plugin wpcode

Upload .php files from a local directory to WordPress. If a snippet with the same name already exists it is updated; otherwise a new snippet is created.

Terminal window
lps snippets push [path]
ArgumentDefaultDescription
path./snippetsLocal directory to read .php files from
FlagDescription
--dryRun / -dShow what would be pushed without making any changes
--plugin / -pTarget plugin: code-snippets (default) or wpcode

Example:

Terminal window
lps snippets push ./wp-snippets
lps snippets push --plugin wpcode

Print all snippets currently on WordPress.

Terminal window
lps snippets list
FlagDescription
--json / -jOutput raw JSON instead of formatted text
--plugin / -pTarget plugin: code-snippets (default) or wpcode

Example output:

Found 3 snippets:
1. price-formatter
Active: ✓
Tags: cli-import
Description: Formats WooCommerce prices
2. redirect-homepage
Active: ✗

Each snippet is stored as a plain .php file named after the snippet. The filename (without extension) becomes the snippet name in WordPress.

snippets/
price-formatter.php
redirect-homepage.php
custom-login-logo.php

To target WPCode instead of Code Snippets, pass --plugin wpcode to any command. The Loopress plugin must be installed and active on your WordPress site for this to work; it exposes the REST endpoint that the CLI uses.

Terminal window
lps snippets pull --plugin wpcode
lps snippets push --plugin wpcode