Sign inBlogSupportContact
General

Read browser cookies from a WordPress macro

Branch a macro based on user preferences, visitor flags, A/B test buckets. Cookie value becomes a chain result you can reference in any downstream step.

3 min read May 2026 get user cookie

Personalization often hinges on a cookie value

An A/B test bucket flag. A "seen the welcome modal" flag. A language preference. A referral-source cookie from a marketing campaign. All stored in the user's browser, all trivially readable in JavaScript — but unreachable from PHP-based automations that run on the server.

If a macro needs to behave differently based on a cookie, you need a way to bring that cookie into the server-side context.

What most people do instead

Read $_COOKIE in a custom pluginRequires PHP. The cookie check becomes a snippet scattered across your theme.
Mirror cookies to user meta with JavaScriptAdds a round-trip to the server. Cookie could change before the meta sync catches up.
Skip personalization entirelyA lot of possible segmentation gets abandoned because reading cookies in macros is awkward.

A better way: one command, cookie as chain result

Run get user cookie -name=cookie_name inside a macro. Get back step1.exists (boolean) and step1.value (the cookie's value). Use them in branch conditions or as inputs to downstream steps.

Macro Builder
Cookie read
Cookie found
Name: ab_test_bucket
Exists: true
Value: variant_b{{step1.value}}

Branch a macro on cookie values. Step 1 reads the cookie. Step 2 branches on step1.value: if "variant_a", send template A; if "variant_b", send template B; if not set, send fallback. Real-time personalization from one macro.

How it works

Reads $_COOKIE[name] from the current HTTP request. If the cookie is present, returns exists=true and value=<string>. If not, returns exists=false. Downstream macro steps can reference both.

1
Pass the cookie name-name=cookie_name
2
Get back exists + valueChain results: step1.exists, step1.value
3
Branch downstream stepsRoute the macro based on cookie state — different templates, different actions.
ParameterValue
-name(required)Cookie name (e.g., ab_test_bucket)
Returnsexists (boolean), value (string)
ScopeCurrent HTTP request only — no cross-user reads
Can be used in

Real example

You run an A/B test on pricing pages. A JavaScript snippet assigns each visitor to "variant_a" or "variant_b" and stores it in a cookie. When the visitor requests a quote, you want different email templates per variant.

The macro triggers on quote request. Step 1: get user cookie -name=ab_test_bucket. Step 2 branches: if step1.value == "variant_a", send "Template A"; else send "Template B". Your variants stay testable without touching your email flows.

Goes further with TrueCommander

Ready?

This is one of 91 commands. All included with every license.

Cookies. The short version.

Essential cookies keep the cart and theme working. Analytics only fire if you say yes. Read our policy.