If you want to use Geo Controller data inside your PHP files or custom templates, there are several flexible integration methods available.
1. Using do_shortcode()
You can render any Geo Controller shortcode using the native WordPress do_shortcode() function:
<?php echo do_shortcode('[cfgeo return="city"]'); ?>
2. Using PHP Class CF_Geoplugin
Geo Controller includes a PHP class you can instantiate and use directly to fetch geo-location data:
<?php if ( class_exists('CF_Geoplugin') ) { $cfgeo = new CF_Geoplugin; $geo = $cfgeo->get(); echo $geo->city; } ?>
3. Using Global Variables
You can also access location data using WordPress global variables provided by the plugin:
Object-oriented style:
<?php global $CF_GEO; echo $CF_GEO->city; ?>
Array style:
<?php global $CFGEO; echo $CFGEO['city']; ?>
These global variables are automatically populated when the plugin initializes and are available throughout WordPress templates and theme files.
Note: Always ensure the plugin is active and loaded before calling its classes or globals, especially in custom environments or headless implementations.
- Globals
- Constants
- Filters
- Utilities
- Security Notes
- HTTP Codes Helper
- Get Current User (ID or Email)
- Quick Access to Geo Fields
- Location Checks (City/Region/Country/Postcode)
- Safe Redirect (Preserving Parameters)
- Cache Invalidation (Global + Popular Cache Plugins)
- Bot/Crawler Detection
- HTTP Requests with Caching (GET/POST)
- Request Sanitizers (GET/POST)
- URL/Host Helpers
- Fragment Caching (W3TC mfunc)
- Defender Cookie (Anti-Abuse Signal)
- Display Flag
- Check if REST is Enabled
- Miscellaneous Utilities