Need a developer?

Fix: WPML for WordPress causes theme to show multiple languages at the same time

The WordPress Multilingual (WPML) plugin offers a comprehensive solution for transitioning from a single language WordPress website to one that supports multiple languages. Once installed, you can add several translations of individual posts and custom posts from within the WordPress admin interface. When viewing a page for a specific language on your site, page content is then generated by pulling in posts for the current language.

Problem: Theme and widgets showing multiple languages

Many themes and plugins will work out of the box with WPML but a common problem is themes and plugins will display content for all languages instead of only the current one. For example, I’ve worked with sites that use the Canvas theme from WooThemes which mostly works with WPML but has a few multilingual usage problems. The bundled widget that shows custom posts to create a slideshow works with WPML in the way you’d expect but the widget that shows custom posts to display customer feedback quotes will show a mixture of languages. This led to a French site showing feedback in both French and English!

Solution: Set suppress_filters to false

A common cause of this is the suppress_filters flag being set to true in the PHP code for the theme or widget that queries for posts to show. This flag tells WordPress to ignore custom filters that plugins apply when querying for posts. WPML add its own filter so that queries will only return posts for the current language. However, there are several ways to query for posts that will inadvertently disable this filter which causes the above problem of posts from all languages being shown. A frequent source of this issue is the get_posts function. By default, get_posts sets suppress_filters to true which disables WPML’s filters! Other querying functions like query_posts set suppress_filters to false by default so will work with WPML as you’d expect.

The solution to fixing the Canvas theme feedback widget was first to locate the PHP code that generated the HTML shown on the frontend and work backwards to find the WordPress query that gathered the list of feedback posts to show. I found the query was being performed by a call to get_posts. After setting the suppress_filters flag to false for this query when calling this function, the widget correctly showed posts only for the current language.