View Categories

Import and Export

Use export to back up snippets or move them to another site, and import to bring them in.

Exporting #

  • One snippet — click Export under the snippet’s name in the snippets list. This downloads a JSON file.
  • Several snippets — select them, choose an export format from Bulk actions, and click Apply.
Format What you get Use it for
Export (JSON) One .json file containing the selected snippets, their scope, tags, and saved configuration values. Moving snippets to another GOCSM site. This is the only format GOCSM can import.
Export (PHP, portable) The snippet source, including its config block and annotations, as a .php file. Sharing a snippet as readable source.
Export (PHP, runnable) A .php file with your configuration values filled in and the code wrapped in its configured hook, ready to run without GOCSM. Using a snippet outside GOCSM, for example in a must-use plugin.

When a PHP format covers more than one snippet, the files download together as a .zip.

Snippets from a GitHub collection are exported as the collection’s definition only — its repository URL and settings — not the snippet code. Importing it recreates the collection and syncs the snippets from GitHub. Recreating GitHub collections needs the Premium or Agency plan; on Pro, they are skipped and listed in the import summary.

A JSON export includes your saved configuration values. If any of them are sensitive, such as API keys, store the file accordingly.

Importing #

  1. In the snippets list, click Import.
  2. Choose a GOCSM JSON export file and click Preview import. Nothing is written yet.
  3. Review the preview, which lists each collection and snippet and what will happen to it.
  4. Choose what to do when a snippet already exists:
    • Skip it (keep what I have) — the default.
    • Overwrite it with the imported version.
    • Import as a new copy.
  5. Optionally check Activate imported snippets after import. Otherwise, imported snippets are added as inactive.
  6. Click Import. A summary shows what was created, updated, skipped, and re-synced.

GitHub collections in the file are created, or re-synced if they already exist, from their repository.

Importing from GitHub #

You can copy the snippets from a public GitHub repository onto your site in one step. The repository needs a snippets.json manifest, the same format GitHub collections use (see Creating Your Own Snippet Library).

  1. In the snippets list, click Import, and scroll to Import from GitHub.
  2. Enter the repository URL. A URL ending in /tree/branch/folder reads that branch and folder.
  3. Optionally enter a branch. Leave it blank to use the branch from the URL, or main and then master.
  4. Click Preview import. GOCSM reads the manifest and each snippet file and shows what will be imported. Nothing is written yet.
  5. Choose what to do when a snippet already exists, and whether to activate the snippets after import, as for a file import.
  6. Click Import.

Each file is checked against the hash in the manifest, and a file that does not match is skipped and listed in the summary. Up to 100 snippets are imported at a time.

Imported snippets become your own standalone snippets: you can edit them freely, and they are never updated from the repository. This import reads public repositories only, and never sends a GitHub token you have configured. To keep a repository’s snippets up to date, or to use a private repository, add it as a GitHub collection instead (Premium and Agency).

Importing from Code Snippets #

GOCSM can import snippets from the Code Snippets plugin, either straight from the same site or from a Code Snippets JSON export.

  1. In the snippets list, click Import, and scroll to Import from Code Snippets.
  2. Choose a source:
    • This site’s Code Snippets — shown when the site has Code Snippets data, even if the plugin is now deactivated.
    • A Code Snippets export file (.json) — made with Export in Code Snippets, on this site or another.
  3. Click Preview import. The preview lists each snippet, the GOCSM type it becomes, whether it already exists, and anything that behaves differently after the move.
  4. Choose what to do when a snippet already exists (skip, overwrite, or import as a new copy).
  5. When importing from this site, leave Deactivate imported snippets in Code Snippets checked unless you have a reason not to.
  6. Optionally check Activate imported snippets after import, then click Import.

Imported snippets are standalone snippets, keep their name, tags, and priority, and are added as inactive unless you chose to activate them. Descriptions are converted to plain text.

How Code Snippets types map to GOCSM #

Code Snippets GOCSM
Run snippet everywhere PHP, context Everywhere
Only run in administration area PHP, context Admin only
Only run on site front-end PHP, context Frontend only
Only run once PHP, context Everywhere, Run once then deactivate checked
Site / admin styles CSS, context Frontend only / Admin only
Site head / footer scripts JS, context Frontend only, location Head / Footer, strategy Blocking
HTML content (shortcode, head, body, footer) HTML, location Shortcode only, Head, Start of body, or Footer. Start of body needs a theme that calls wp_body_open().
Conditions Not imported.

Imported PHP snippets use the plugins_loaded hook, matching when Code Snippets ran them, so they keep working the same way. You can change the hook afterwards in the snippet’s scope settings.

Two differences to check after importing:

  • Admin only and Frontend only are stricter in GOCSM. Code Snippets’ admin snippets also ran on AJAX requests, and its front-end snippets also ran on REST API requests. GOCSM’s Admin only context skips AJAX, and Frontend only skips REST. The preview flags these snippets. If one handles AJAX or REST requests, set its context to Everywhere.
  • Shortcodes change name. Content that embeds an HTML snippet with [code_snippet id="…"] must be updated to GOCSM’s [gocsm_snippet id="…"].

Running the same snippet twice #

A PHP snippet active in both plugins declares its functions twice, which stops the site with a fatal error. To prevent this:

  • Deactivate imported snippets in Code Snippets turns off each original as it is imported.
  • A snippet imported from this site’s Code Snippets cannot be activated in GOCSM while its original is still active in Code Snippets. Deactivate the original first.

When importing from an export file, GOCSM cannot see the original site, so deactivate the snippets in Code Snippets yourself before activating them in GOCSM.

Re-importing from the same site recognizes snippets that were already imported, even if you renamed them in GOCSM, and treats them as existing snippets. Multisite network snippets are not imported.

Choosing what to import #

The Code Snippets preview has an Import checkbox for each snippet and a select-all checkbox. Only selected rows are imported or deactivated in Code Snippets. Activate is available only for originals that are already active; uncheck individual rows or the activation option to leave those copies inactive. If a source snippet changes after preview, preview again before importing.

The optional Replace HTML shortcode references in imported code updates references to successfully imported HTML snippets using their new GOCSM IDs. A second option also updates posts and pages you can edit, preserving previous content through WordPress revisions. Escaped shortcodes and IDs without a successfully imported HTML target are left alone. Referenced snippets must be active to display.