PHP Integration

1. Using WordPress Shortcodes in PHP

The simplest method is to execute a Geo Controller shortcode using the native WordPress do_shortcode() function.

For example, display the visitor’s detected city:

echo esc_html(
    do_shortcode('[cfgeo return="city"]')
);

Retrieve the visitor’s country:

echo esc_html(
    do_shortcode('[cfgeo return="country"]')
);

Or retrieve the country code:

echo esc_html(
    do_shortcode('[cfgeo return="country_code"]')
);

This method is useful when you already use Geo Controller shortcodes throughout your website and want to reuse them inside PHP templates.

Note: Shortcodes must be registered before calling do_shortcode(). Execute these examples during normal WordPress rendering, after the plugins have initialized.

Was this page helpful?