12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Mar 25, 2020

[Condition] US State

Sridhar Katakam

This members-only tutorial provides the steps to register a custom Oxygen condition using which elements can be output to users visiting from a specific state in the US using the API from ipapi.co.

We are going to add "US State" in the conditions list under the "Other" category with equals and not equals operators.

Meaning, you can either output or NOT output any element in the Oxygen builder to visitors from a specific US state.

Note: You can easily modify this to check against regions (states) of any country by replacing the state names in the code.

Use Case

Say you own a tours attraction website based in the US. You could show one Section for visitors from New York and another for visitors from a different state say, Florida.

Note that the great thing about Oxygen's conditions is that content gets output or printed on the front end conditionally and it is not that it is just hidden or shown using CSS’ display property.


IP and State detection may not work reliably when there is caching (especially at the server level) involved. You may need to add the page(s) where you are implementing this to your cache plugin's exclusion list.

You are advised to test this solution first before using it in production.

Step 1

Install and activate Code Snippets plugin.

Go to Snippets > Add New.

Title: [Function] Get IP Address


This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.