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'
);