Showing different ads per language with WPML

WPML is one of the most prominent solutions to create multilingual WordPress sites. It is so popular among our users that I decided to dive into its features to see how ads work on multilingual sites. 

We even used the plugin ourselves when translating wpadvancedads.com into German and became a certified WPML partner.

In a nutshell

Contents

  • By default, ads and ad groups are set to non-translatable by WPML. You can make them translatable like any other post type or taxonomy.
  • Display conditions on the ad edit screen show the information for the selected language.
  • Options are not language-specific. It is best to use the All languages option when editing them.
  • The Placements page shows the ads and groups depending on the language. An ad selected in one language will automatically cause the correct translated version to show in the other languages, too.
  • Advanced Ads Pro comes with a WPML display condition to show ads by selected language.

Translating ads?

With Advanced Ads and WPML combined, you have multiple options to handle ads. You can manage ads for each language, you can use the same ads for both versions, or just handle a few ads with translations, but not others.

Here are a few scenarios when it makes sense to have different ads per language:

  • Your ad content or image contains text that only makes sense in one language but not the other.
  • You want to track the performance of an ad per language.
  • You want different target URLs per language.
  • Using display conditions based on translated content, e.g., Specific Pages.

I have seen all of these scenarios implemented by our users. 

Not everyone with a translated website needs different ads per language, though. I have also seen many publishers using ad networks like AdSense. They don’t have to worry about translations because AdSense automatically delivers the ad’s content based on the visitor.

Please find the options you have (not) translating your ads managed with Advanced Ads and WPML below.

How to enable translations for ads

By default, WPML does not add its translation interface to ad edit pages. This means that you will always have access to your complete ad list in the frontend and backend, regardless of the language you are currently switched to.

See Also  How to uninstall faceit from computer

I have seen this default behavior to be different in older WPML installations and translating ads by default.

You can enable translations for ads in one of two sections:

  • WPML > Settings > Post Types Translation and look for the row starting with Ads (advanced_ads).
  • As mentioned, the selected option in this line should be Not translatable by default, the right column in the table.

    To set ads to being translatable you need to change the option to “Translatable – only show translated items”, like on the screenshot below.

    The option – “Translatable – use translation if available or fallback to default language” – does not differ from the translation option right now, and you can just ignore it.

  • You can also make ads translatable through the “Multilingual Content Setup” box on the ad edit screen.
  • The behavior of translated ads

    If you are familiar with how WPML translates posts and pages, you already know what translating ads feels like. Once you create a new ad, it will automatically be bound to the language version you made it. You can create translated versions as well through the WPML options, which are then magically attached.

    It is best to see on the ad list and when switching between the language versions of your site. As you can see below, my English site has two ads, with “Ad – English” having a German equivalent already linked from the ad list.

    Ad list translated with WPMLAds overview page with translations showing up.

    Using display conditions with WPML

    Whether you are using translated ads or not, Display Conditions will always be language-specific.

    Imagine you have an English landing page called “About Us”, and a German translated version called “Über Uns”. You want to display a specific ad on these pages.

    When you go to the ad edit page and add the Specific Pages Display Condition, you will only find the page with the language you are using your backend in.

    Non-Translatable ads

    With English being the default language and the ad set to be untranslated, you will never be able to display it based on a display condition from the German site, like on the “Über Uns” page only.

    Translatable ads

    With translatable ads, you can choose the “About Us” page for the English ad and “Über Uns” for the German translation. 

    See Also  How much juice does one orange make

    You will need to set these conditions for both ads. They are not “translated” automatically.

    The same applies to most other conditions and options, like visitor conditions or tracking.

    Translating ad groups

    WPML allows translating ad groups. This feature is also disabled by default. You can enable this in WPML > Settings > Taxonomies Translation. Look for the Ad Groups & Rotations (advanced_ads_groups) row.

    You also need to match the translated groups of the different languages in WPML > Taxonomies Translation.

    The Groups page only shows ads for the current language. E.g., you select an English ad while editing the group for English. Now you switch to German. If the previous English ad is connected to a German translation, the German ad will appear in the group. 

    If there is no German translation, the German won’t show it in the backend and frontend.

    As far as we see it, assigning your ads, translated or not, to translated groups seems the best option to deliver ads based on the language. You can use that group in a placement or add it directly to your site in a widget or using the shortcode.

    Translating placements

    The Placements page shows the same placements for all languages.

    In the Item field, only ads and groups for the current language show up. E.g., you select an English ad while editing the placements for English. Now you switch to German. If the previous English ad is connected to a German translation, then the German ad will show up as the Item. If there is no German translation, the Item field will stay empty.

    When you assign a translated ad or group in any language, the translated version of that ad will show up in the frontend for the correct version of the site.

    Advanced Ads Pro also offers the option to add display and visitor conditions to placements. So you could use the WPML display condition to assign your placements to specific languages.

    Edit untranslated options in “all languages” view

    As general advice, you should edit untranslated ads, untranslated groups, and other options and pages in Advanced Ads in the “all languages” view in your backend. 

    Otherwise, we have seen some information getting lost when changing the backend language.

    See Also  How to smoke terp sauce

    The WPML language condition

    Advanced Ads Pro comes with a WPML language display condition. This option comes in handy when you want to display an untranslated ad in a general position, like a widget or through a placement, and limit it to specific translations of the site.

    E.g., Your “Buy Now” ad uses the Before Content placement, but you only want to inject it into English sites and not the German ones.

    Translating the Ad Label option

    You can translate the Ad Label option under Advanced Ads > Settings > General using the String Translation plugin by WPML.

    ad label option

  • Enable the WPML String Translation plugin.
  • Go to WPML > String Translation.
  • Select admin_texts_advanced-ads in the domain filter.
  • Click on the translations link in the String column.
  • Enter the translations and mark them as complete.
  • WPML string translations for Advanced Ads optionsThis is how it looks with the ad label translated into German.

    Known issues

    When switching the language in the backend, some options disappear.

    Use the “all languages” option if you work on untranslatable ads, groups, or other Advanced Ads-related pages to not run into this problem.

    A user reported that he had to set the ad group taxonomy to “translatable” in the “Multilanguage Settings” panel inside the ad edit page to save ad weights.

    Redis Object Cache

    The translation doesn’t seem to work when Redis is used on the server, and the Redis Object Cache plugin is enabled.

    The solution is to add Advanced Ads as an exception to Redis by adding the following line into your wp-config.php:

     div {
    	overflow: auto;
    }
    
    .shcb-language {
    	border: 0;
    	clip: rect(1px, 1px, 1px, 1px);
    	-webkit-clip-path: inset(50%);
    	clip-path: inset(50%);
    	height: 1px;
    	margin: -1px;
    	overflow: hidden;
    	padding: 0;
    	position: absolute;
    	width: 1px;
    	word-wrap: normal;
    	word-break: normal;
    }
    
    .hljs {
    	box-sizing: border-box;
    }
    
    .hljs.shcb-code-table {
    	display: table;
    	width: 100%;
    }
    
    .hljs.shcb-code-table > .shcb-loc {
    	color: inherit;
    	display: table-row;
    	width: 100%;
    }
    
    .hljs.shcb-code-table .shcb-loc > span {
    	display: table-cell;
    }
    
    .wp-block-code code.hljs:not(.shcb-wrap-lines) {
    	white-space: pre;
    }
    
    .wp-block-code code.hljs.shcb-wrap-lines {
    	white-space: pre-wrap;
    }
    
    .hljs.shcb-line-numbers {
    	border-spacing: 0;
    	counter-reset: line;
    }
    
    .hljs.shcb-line-numbers > .shcb-loc {
    	counter-increment: line;
    }
    
    .hljs.shcb-line-numbers .shcb-loc > span {
    	padding-left: 0.75em;
    }
    
    .hljs.shcb-line-numbers .shcb-loc::before {
    	border-right: 1px solid #ddd;
    	content: counter(line);
    	display: table-cell;
    	padding: 0 0.75em;
    	text-align: right;
    	-webkit-user-select: none;
    	-moz-user-select: none;
    	-ms-user-select: none;
    	user-select: none;
    	white-space: nowrap;
    	width: 1%;
    }
    ]]>

    define( 'WP_REDIS_IGNORED_GROUPS', array('advanced-ads') );

    Code language: PHP (php)

    Thomas

    Starting in 2009, Thomas’ own word game website grew to 40 MM page impressions per month. He then built Advanced Ads to help his colleagues to place ads and test different ad positions and networks tests without any coding skills. Thomas now enjoys improving the product for our more than 150,000 users worldwide.

    Rate this post
    Back to top button