-
Notifications
You must be signed in to change notification settings - Fork 0
Conditional Loading
Pro feature. Conditional loading requires an active Scriptomatic Pro licence. A 3-day free trial is available — visit Scriptomatic → Account.
Restrict when scripts are injected using stacked AND/OR rules. Conditions can be set independently per inline script and per external URL entry.
| Type key | Label | What it matches |
|---|---|---|
front_page |
Front page only | The site's configured front page (is_front_page()) |
singular |
Any single post or page | Any single post, page, or custom post type (is_singular()) |
post_type |
Specific post types | One or more selected public post types |
page_id |
Specific pages / posts by ID | One or more specific post/page IDs (comma-separated) |
url_contains |
URL contains (any match) | The current URL contains any of the specified substrings |
logged_in |
Logged-in users only | The current visitor is logged in |
logged_out |
Logged-out visitors only | The current visitor is not logged in |
by_date |
Date range | Current date falls within a YYYY-MM-DD start/end window |
by_datetime |
Date & time range | Current date-time falls within a YYYY-MM-DDTHH:MM window |
week_number |
Specific week numbers | Current ISO week number is in the specified list |
by_month |
Specific months | Current month is one of the selected months (1–12) |
Each conditions panel has a logic toggle:
- AND — all rules must match for the script to load
- OR — any single rule matching is sufficient
When no conditions are configured (or the rules list is empty), the script loads on all pages.
External script URLs each have their own independent conditions panel — a URL loads only when its own conditions pass. The inline script's conditions are evaluated separately.
The conditions are stored and accepted by the REST API and WP-CLI as a JSON object:
{
"logic": "and",
"rules": [
{ "type": "front_page", "values": [] },
{ "type": "post_type", "values": ["post", "page"] },
{ "type": "url_contains", "values": ["/blog/", "/news/"] }
]
}| Type |
values format |
Example |
|---|---|---|
front_page |
[] (empty) |
{"type":"front_page","values":[]} |
singular |
[] (empty) |
{"type":"singular","values":[]} |
post_type |
Array of post type slugs | {"type":"post_type","values":["post","product"]} |
page_id |
Array of integer IDs | {"type":"page_id","values":[42,99]} |
url_contains |
Array of substrings | {"type":"url_contains","values":["/shop/"]} |
logged_in |
[] (empty) |
{"type":"logged_in","values":[]} |
logged_out |
[] (empty) |
{"type":"logged_out","values":[]} |
by_date |
["YYYY-MM-DD","YYYY-MM-DD"] (start, end) |
{"type":"by_date","values":["2026-01-01","2026-03-31"]} |
by_datetime |
["YYYY-MM-DDTHH:MM","YYYY-MM-DDTHH:MM"] |
{"type":"by_datetime","values":["2026-03-01T09:00","2026-03-01T17:00"]} |
week_number |
Array of ISO week numbers (1–53) | {"type":"week_number","values":[1,2,3]} |
by_month |
Array of month numbers (1–12) | {"type":"by_month","values":[11,12]} |
Pass conditions via --conditions:
# Front page only
wp scriptomatic script set --location=head \
--content="console.log('front');" \
--conditions='{"logic":"and","rules":[{"type":"front_page","values":[]}]}'
# Logged-in users only OR front page
wp scriptomatic script set --location=footer \
--file=/tmp/my.js \
--conditions='{"logic":"or","rules":[{"type":"logged_in","values":[]},{"type":"front_page","values":[]}]}'Pass conditions as an optional JSON parameter in the request body:
curl -X POST https://example.com/wp-json/scriptomatic/v1/script/set \
-H "Authorization: Basic $(echo -n 'admin:xxxx xxxx xxxx xxxx xxxx xxxx' | base64)" \
-H "Content-Type: application/json" \
-d '{
"location": "head",
"content": "console.log(\"hello\");",
"conditions": "{\"logic\":\"and\",\"rules\":[{\"type\":\"front_page\",\"values\":[]}]}"
}'← Home