Skip to content

Export & Import

The top-level export and import commands provide a quick way to migrate CodeSnippets data to and from a file. Unlike snippets push/pull, these are designed for one-off migrations rather than day-to-day Git workflows.

Download all snippets from WordPress and write them to a single file.

Terminal window
lps export [output]
ArgumentDefaultDescription
outputsnippets.jsonDestination file path
FlagDescription
--format / -fOutput format: json (default), php

Examples:

Terminal window
# Export as JSON
lps export
# Export as a PHP array (useful for including in a theme)
lps export --format php snippets.php
<?php
/**
* CodeSnippets Export
* Generated by loopress CLI
*/
return [
'price-formatter' => [
'code' => <<<PHP
// snippet code here
PHP,
'active' => true,
'tags' => ['cli-import'],
],
];

Upload snippets from a previously exported file back to WordPress.

Terminal window
lps import [input]
ArgumentDefaultDescription
input(required)Path to the source file

Example:

Terminal window
lps import snippets.json

When to use export/import vs snippets push/pull

Section titled “When to use export/import vs snippets push/pull”
ScenarioRecommended command
Day-to-day development, version controlsnippets push / snippets pull
One-time migration between two sitesexport + import
Backup before a big changeexport snippets-backup.json
Sharing snippets as a PHP fileexport --format php