How to include CF GeopPlugin in PHP?

In PHP you can use WordPress function do_shortcode()

Example:

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

or directly using PHP class:

<?php
if(class_exists("CF_Geoplugin")){
    // 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:

<?php
$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';
else
    echo 'Hakuna Matata';
?>

 

About the author

Login

Lost your password? Register

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