PHP Integration

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.

Was this page helpful?