Using the free TranslatePress plugin, you can set up a multilingual website in WordPress to internationalize your content and grow your audience. If you are monetizing such a website with ads, delivering those explicitly for the specific user’s language makes sense for several reasons.
Not only will you be able to deliver relevant content to your users in their own language. But you can also improve your conversion rates by redirecting visitors to targeted pages in their language. This enhances the overall user experience and makes them more likely to take the desired action.
In this tutorial, you’ll learn how to use Advanced Ads to deliver ads based on the TranslatePress language of your content.
Targeting ads by language-specific URL parameter
If you have enabled subdirectories for the default language, then using Advanced Ads Pro‘s URL parameter display condition is the most convenient way to target language-specific ads. That’s because, in this setting, TranslatePress inserts a country code for each language in the URL slugs, including one for the default language.
Such a URL slug could look like this for the English version:
https://wpadvancedads.com/en/advanced-ads-pro/. In contrast, the German equivalent might look like this:
If you want to show ads in English on your English language posts, you will target ads to pages with URL slugs that contain “/en/”.
But if you want to disable a subdirectory for the default language, you can also use the URL parameter condition to target this particular content. Invert the condition setting to show the English ads only on pages that do not contain “/de/“.
You can also target ads on archive pages, such as category pages, by using URL parameters. Just make sure their URL slugs contain the specific country code.
Advanced Ads Pro’s time-saving feature of adding conditions to entire placements is extremely convenient in this situation. You can create a custom placement for specific languages, meaning you don’t have to set individual conditions for every ad unit.
Targeting ads using the TranslatePress shortcodes
If you don’t want to use the URL parameter condition, you can use TranslatePress’ shortcodes to show or hide content depending on the chosen language. Here’s how you would set this up:
- Create an ad group for each language you have added in TranslatePress and for which you want to show specific ads.
- Add your language-specific ads to the corresponding ad group.
- Create a new ad unit with the “Plain text and code” ad type. You will use this ad unit solely in order to show the appropriate ad group depending on the language of the content.
- Insert the TranslatePress shortcodes, which recognize the selected language and output the enclosed contained content in case of a positive match.
The shortcode to show a specific ad group only in content assigned to an English (US) translation looks like this:
[trp_language language="en_US"] [the_ad_group id="836"] [/trp_language]Code language: JSON / JSON with Comments (json)
- Put the shortcodes of your ad groups between the TranslatePress shortcodes. You can retrieve these shortcodes by clicking the “Show usage” link under the ad group’s name.
Example of language-specific ads and TranslatePress shortcodes
In the following example, you can see what controlling the injection of an English and a German ad group to the related content looks like.
You can now assign this ad unit that you will use to control the language-specific ad output to a placement and automatically insert it into the content of your website. If a user now calls up a page that TranslatePress recognizes as English (US), WordPress will execute this shortcode and, lastly, will include the ad group.
Obtain the code as well as the URL parameter of each language under Dashboard > Settings > TranslatePress > General.
Of course, adding multiple ads to this group is possible so that different ads may rotate at this position.
And that’s all you need to know to deliver your ads tailored to the served content’s TranslatePress language. I hope your advertisements’ significantly higher click-through rates will reflect this improved targeting.