Skip to content

Documentation

SnippetCrate

Adding your first snippet, choosing a scope, the shortcode, importing and exporting, and what happens when a snippet errors.

// Getting started

Install it

  1. Install from Plugins → Add New, or upload the snippetcrate folder to /wp-content/plugins/.
  2. Activate it on the Plugins screen.
  3. Open SnippetCrate from the admin menu.

SnippetCrate needs WordPress 5.2 or newer and PHP 7.4 or newer. Only administrators — users with manage_options — can see any of it.

Your first snippet

  1. Click Add New Snippet.
  2. Give it a name you will recognise in six months.
  3. Choose the language: PHP, JavaScript, CSS or HTML.
  4. Choose the scope — where it runs. See below.
  5. Paste the code. The editor checks the syntax as you type.
  6. Save & Activate.

PHP is validated on your server and JavaScript in your browser, so a snippet that does not parse cannot be saved at all. That check is on syntax, not on whether the code does what you meant.

// Scope

Scopes: where a snippet runs

Every snippet has a scope, so nothing runs anywhere you did not intend. The scope you can pick depends on the language.

Global

PHP only. Runs on every front-end request, the way a snippet in functions.php would.

Header / Footer

Printed into wp_head or wp_footer. Available to PHP, JavaScript, CSS and HTML.

Shortcode

Renders only where you place it. The exact shortcode is shown on the edit screen.

Global snippets are hooked to wp, which never fires in wp-admin, in REST requests or in cron. A broken global snippet therefore cannot lock you out of your own dashboard.

Running one in a single place

Set the scope to Shortcode and drop [snippetcrate_snippet id="X"] wherever you want it, where X is the id shown on the edit screen.

// Safety

When a snippet goes wrong

Two separate safety nets, and it is worth knowing which one catches what.

Before saving

PHP is parsed with token_get_all() using the TOKEN_PARSE flag, which fully parses the code without running any of it. Code that does not parse is rejected and the error is shown in the editor.

At runtime

Every execution is wrapped in try / catch. If an active snippet throws, it is deactivated immediately, so the next page load no longer runs it.

Being straight about the limit: this contains anything PHP can throw, which is the overwhelming majority of mistakes. It cannot rescue you from a snippet that loops forever or exhausts the memory limit, because PHP cannot catch those. Test substantial snippets on a staging site first.

// Library

Managing more than a handful

Duplicate any snippet as a starting point for the next one.

Filter the list by status, language, tag or date.

Bulk activate, deactivate, export or delete.

Import and export the whole library as JSON, or export just your PHP snippets to a .php file.

// FAQ

Questions

Who can add or run snippets?

Only administrators, meaning users with the manage_options capability. Every admin screen and every REST endpoint is capability-checked and nonce-protected. On a multisite network a Super Admin is required as well.

Which languages can use which scope?

PHP, JavaScript, CSS and HTML are all supported. Only PHP can use the Global scope; every other language runs in the header, the footer, or through the shortcode.

Is JavaScript, CSS or HTML ever evaluated?

No. Only PHP is executed. The others are printed as markup into the header or footer.

Does the plugin load anything from a third-party server?

No. The admin app, the code editor and the fonts are all bundled with the plugin and served from your own site.

Does uninstalling remove my snippets?

Deleting the plugin removes its database table and its options. Deactivating the plugin leaves your snippets intact.

Still stuck?

If something here is wrong or missing, tell us and we will fix it — then write it down for the next person.