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:
echo do_shortcode('[cfgeo return="city"]');
2. Using PHP Classes and Helpers
The legacy CF_Geoplugin
class is deprecated. Please use the new CFGP_U
and CFGP_API
classes instead.
// Preferred usage $data = CFGP_U::api(); // Full structured geodata array $country = $data['country'] ?? ''; // Safe access to fields // Access a single field from the API via helper $country = CFGP_U::api('country'); // e.g. "Germany" $countryCode = CFGP_U::api('country_code'); // Explicit lookup via the API class (advanced) $response = CFGP_API::lookup('8.8.8.8', ['dns' => true]); // Always validate keys defensively if (is_array($response)) { $city = $response['city'] ?? ''; }
For more information about deprecated code and migration details, please read:
Deprecated Code Notice
3. Using Global Variables
You can also access location data using WordPress global variables provided by the plugin:
Array style:
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