How to include CF GeopPlugin in PHP?

In PHP you can use WordPress function do_shortcode()


<?php echo do_shortcode('[cf_geo return="city"]'); ?>

or directly using PHP class:

    // include plugin class
     $cf_geo = new CF_Geoplugin;
     // get data
     $geo = $cf_geo->get();
     // print data
     echo $geo->city;

You are free to decide what method is best for you to use.

Later you can use data like:

$country = strtoupper($geo->country_code);
if(in_array($country, ['US','UK']) !== false)
    echo 'Hello World';
else if(in_array($country, ['DE','GB']) !== false)
    echo 'Hallo Wereld';
    echo 'Hakuna Matata';


About the author


Lost your password? Register


Your personal data will be used to support your experience throughout this website, to manage access to your account, and for other purposes described in our privacy policy.

Lost your password? Login