Global Variables
Global Variables let you define named values that persist across page loads, within a user’s session, or site-wide. This enables cross-page state without JavaScript or cookies managed manually — ideal for multi-step funnels, personalization chains, and feature flags.
Variable Scopes
| Scope | Lifetime | Use Case |
|---|---|---|
session | Until browser session ends | Multi-step form tracking, funnel state |
user | Persistent per logged-in user (WP usermeta) | Dark mode preference, onboarding step |
site | Global for all visitors | Feature flags, maintenance mode, sale state |
Defining a Global Variable
In Settings → Vector Expressions Pro → Global Variables, click Add Variable and configure:
- Key: The identifier used in expressions (e.g.,
sale_active) - Scope:
session,user, orsite - Default Value: The resolved value when no stored value exists
Reading Variables in Expressions
Global variables are accessible via the global data root:
{{ global.sale_active ? "50% OFF — Today Only!" : "" }}
{{ global.onboarding_step == "3" ? "is-step-3" : "" }}
{{ global.user_theme | default "light" }}
Writing Variables
Variables can be updated via the REST API endpoint provided by Pro:
POST /wp-json/vector-expressions-pro/v1/globals
{
"key": "sale_active",
"value": "true",
"scope": "site"
}
Requires authentication with manage_options capability for site scope, or read for session/user scopes.
Use Case: Feature Flag
- Define a
site-scoped variable:feature_new_checkout = false - Use it to conditionally show a block:
Visibility: Show if True → {{ global.feature_new_checkout == "true" }}
- Flip the flag via the REST API to instantly enable the feature for all visitors, no deployment required.