How to publish content based on the country under WordPress

Unusually, I started working on the configuration of Quelbazar blog today. Program: a solution to customize some content of the blog based on the country of origin of the visitor. Specifically, I wanted to include country-specific ads. Because it doesn't help to offer Swiss ads to a french visitor, for example.

The method is quite simple, because others thought before us: there is a wordpress plugin that does it right: Custom Content By Country.

This plugin works through "shortcodes", so I let you go see the syntax in the documentation of the plugin. For the simple reason that I don't know how to insert a shortcode into the article unless it is interpreted…

The plugin works without other articles, but my goal was to use it in a widget. Article Using shortcodes everywhere gives us the solution: in the file functions.php (the one in wp-includes), add:

add_filter ('widget_text', 'shortcode_unautop');
add_filter ('widget_text', 'do_shortcode');
I did it at the beginning of the file inside the php code. Shortcodes are then interpreted in widgets, allowing me to offer the Swiss for the Swiss pub, and French advertising for others. There, on the right, the 2nd from the top pub.
 
[CBC country=”ch” show=”y”]And at the same time, it allows me to tell you that you are visiting this site from the Switzerland![/CBC]
[CBC country=”fr” show=”y”]And at the same time, it allows me to tell you that you are visiting this site from the France![/CBC]
[CBC country=”be” show=”y”]And at the same time, it allows me to tell you that you are visiting this site from the Belgium![/CBC]
[CBC country=”us” show=”y”]And at the same time, it allows me to tell you that you visit this site from the USA! Or via a RSS reader.[/CBC]
[CBC country=”ch,fr,be,us” show=”n”]And at the same time, it allows me to tell you that you are visiting this site from a country which is neither the Switzerland, the France nor the Belgium and or the USA. Or so that your IP is not geo-referenced.[/CBC]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *