Run-when conditions
Run-when conditions let you attach precise execution rules to a snippet, restricting it to specific pages, post types, user roles, or any custom logic you define.
Watch this part of the walkthroughRun Conditions at 8:56, opens on YouTubeTargeting with conditions
A snippet's scope is the coarse gate: it separates front-end execution from admin execution. Run-when conditions go further. They are a rule builder that restricts exactly when a snippet executes within that scope.
You can combine multiple conditions in a single rule set. For example, you might target a snippet to run only on singular posts of a specific post type, only for logged-in users with a particular role. This level of targeting keeps snippets lean and avoids loading code where it is not needed.
Authoring advanced conditions is a Pro feature
Pro
The advanced rule builder and advanced condition subjects require SnipCraft Pro. The three basic subjects (URL path, login state, and user role) are available in all editions without a Pro license.Advanced subjects (Pro)
Pro
Advanced condition subjects require SnipCraft Pro to author. The three basic subjects (URL path, login state, and user role) remain available in all editions. Once set, all conditions are enforced in every edition regardless of license. Rule sets support match-all or match-any logic and can contain up to 20 rules. The evaluator is fail-closed: any rule it cannot resolve prevents the snippet from running.Advanced subjects let you build precise targeting around the current request, the WordPress query, or a server-side time window. For scheduling a snippet to run on a timer rather than on a page load, see scheduling.
Query facts
These subjects are resolved after the main WordPress query (the wp hook) and are fail-closed before that point.
- Page type: matches WordPress conditional tags: front page, home, single, page, singular, archive, search, 404, or author.
- Post type: matches the post type of the currently queried object.
- Post ID: matches one or more specific post IDs.
- Taxonomy term: matches whether the queried object belongs to a specific term in a given taxonomy.
- Post meta: matches the presence or value of a custom field on the queried post.
Request facts
These subjects are resolved from the HTTP request and are available early (at the init hook).
- URL parameter: matches the presence or value of a query string parameter.
- HTTP referrer: matches the referring URL by exact value, prefix, or substring.
- User capability: matches whether the current user has a specific WordPress capability.
- Device type: matches mobile or desktop, resolved via WordPress's user-agent detection.
Dynamic
- Schedule window: restricts execution to a date range, specific days of the week, or a time-of-day window on the server clock.
- Custom PHP expression: evaluates an arbitrary PHP boolean expression at runtime. Requires the edit-PHP capability to author.
Conditions are always enforced
Once conditions are set on a snippet, they are evaluated on every execution, in every edition, including the free edition. This is an intentional design decision: downgrading from Pro to the free edition never silently removes a snippet's targeting or causes it to run where it should not.
You lose the ability to author new conditions without Pro, but existing conditions on any snippet remain fully active and enforced.
Related
For the coarse environment gate, see scopes. To unlock condition authoring and all other Pro features, see SnipCraft Pro.