Location Conditional Content
A lightweight WordPress plugin that lets you show or hide content and Elementor elements based on the visitor's country
by Rizwan Ilyas · github.com/rizwanali490/location-conditional-content · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/rizwanali490/location-conditional-content/archive/refs/heads/main.zipA lightweight WordPress plugin that lets you show or hide content and Elementor elements based on the visitor's country — similar to the geolocation feature in If-So Dynamic Content.
Perfect for geo-targeted offers, region-specific messaging, country-based promotions, or compliance requirements.
Features
-
Shortcode support
[location_conditional country="AF,US" not="no"]Your content[/location_conditional] -
Elementor integration
New "Location Visibility" section in the Advanced tab of every widget, section, and container
→ Enable/disable per element
→ Show or hide based on selected countries
→ Multi-select country dropdown (full ISO 3166-1 list) -
Accurate country detection
Uses ipapi.co (free tier: 30,000 requests/month)
Cached for 24 hours per IP to minimize API calls -
No global performance hit
Only conditional elements are affected
Compatible with Elementor caching when you set Cache Setting → Inactive on conditional elements
Installation
- Download and unzip the plugin
- Upload the
location-conditional-contentfolder to/wp-content/plugins/ - Activate the plugin through Plugins → Installed Plugins in WordPress
- (Optional) Use the shortcode or edit Elementor elements
No settings page — controls live inside Elementor or via shortcode.
Usage Examples
1. Shortcode (anywhere in content)
[location_conditional country="AF"]
<div class="alert alert-success">Special offer for visitors in Afghanistan!</div>
[/location_conditional]
[location_conditional country="US,CA" not="yes"]
<p>This message is hidden in the United States and Canada.</p>
[/location_conditional]
2. Elementor (recommended for visual builder)
-
Edit page with Elementor
-
Select any widget, section, or container
-
Go to Advanced tab → Location Visibility
-
Enable the condition
-
Choose Show or Hide mode
-
Select one or more countries
-
(Important) In the same Advanced tab → set Cache Setting to Inactive→ This prevents Elementor from caching the element and showing stale geo-content
How Country Detection Works
-
Visitor IP → https://ipapi.co/{ip}/country/ (returns ISO 3166-1 alpha-2 code, e.g. "AF")
-
Result cached 24 hours using WordPress transients
-
Handles proxies / Cloudflare via standard forwarded headers
-
Fallback: hide content if lookup fails
Requirements
-
WordPress 6.0+
-
PHP 7.4+
-
Elementor (free version is enough)
Notes & Limitations
-
Elementor Caching: Must manually set Cache Setting → Inactive on each conditional element (or disable Element Caching globally) — otherwise cached output may be shown to wrong visitors.
-
Country-level only (no cities/regions in this version)
-
Relies on third-party free API (ipapi.co) — rate limits apply on very high traffic
-
Accuracy ~95–98% for country detection (typical for IP geolocation)