DocsCode Snippets

Snippet types, run modes and conditions

What each snippet type can do — PHP run modes, JavaScript loading, CSS delivery, HTML placement, JSON config — and conditions for where, for whom and when it runs.

PHP#

Where: everywhere, the site, the dashboard, AJAX, the REST API or scheduled tasks. Who: everyone, logged-in or logged-out visitors. Plus an order, and “only while these snippets are active”. Then a mode:

ModeThe code…
RunRuns on each request, at a timing: as plugins load, at init, or once WordPress knows the page (needed for page conditions).
HookIs the callback of one action or filter, with $args. A filter that fails or returns nothing keeps its original value.
ShortcodeReturns a shortcode’s output, with $atts.
REST endpointAnswers a route you define (namespace, route, methods, who may call it), with $request.
Run onceOnly runs when you click Run now — for one-off data changes.
// Hook: filter the excerpt length (mode Hook, filter excerpt_length)
return 24;

JavaScript#

Placed in the head, at the start of the body, or in the footer; loaded inline, deferred, async or as a module; from your code or a script URL; after dependencies (WordPress script handles or other snippets). Uncaught errors in the browser are reported back to the snippet’s log.

CSS#

Delivered inline, as a cached file, or automatically; optionally minified. It loads after Native AI’s own styles, and a screen-width condition becomes a media query.

HTML#

Printed at a position in the page, or as a shortcode.

JSON config#

A value your code reads with nai_config('KEY') in PHP — and, if you choose, as window.NAI_CONFIG in JavaScript.

Conditions#

Where, for whom and when a snippet runs uses the same display conditions as templates, plus three rules made for code: the address (URL), the device, and uses a template. JavaScript snippets can also use the browser rules (screen width and more).

Site Scripts#

Three quick boxes — head, start of body and footer — for things like a verification tag or a chat widget. Each is an HTML snippet on the same engine, and it goes live when you save.

Page & element code#

Lists the custom code that lives in pages, templates and elements, so nothing is hidden. See Custom code in pages and elements.