SOLVED: Template condition does not work as expected with Polylang & WPML

Browser: Chrome 138.0.7204.158
OS: Windows

Hi team,

I have a bilingual website (with polylang plugin) where there are two pages for the blog and two archive templates for the post archives for the languages. As shown in this screenshot, each template has an “individual” condition that connects the template to a page with the same language.

The problem is that Bricks 2.0 does not allow the individual condition in the templates to select two different pages. If we try to select two different pages, it will automatically be set to similar pages or the same blog pages.

Reverting to Bricks 1.12.4 fixes the problem.

UPDATE:

Even in single post I can’t select populated content correctly and it changes automatically. Actually I want to select Persian post for Persian single post and English post for English single post as populated content. But after reloading populated content is automatically reversed. That is, English post is selected for Persian single post and Persian post is selected as populated content for English single post!

Hi @HOSEIN,

Prior to 2.0, did you set the Bricks template post type to be translatable with Polylang, or did you leave it as untranslatable and used it that way?

Hi Charaf,

Yes, I had set it to be translatable. But it seems that in Bricks 2.0, the bricks template option has been removed from the post type list and is enabled by default. Of course, I’m not sure if this has any effect on the problem.

@charaf Seems to be related to the wpml-config.xml file which comes with Bricks 2.0 as discussed here.

See The wpml-config.xml file - Polylang.

1 Like

Hi @aslotta,

We generally do not recommend the approach of making Bricks templates non-translatable (see: How to use Polylang with Bricks – Bricks Academy). However, if you find that this method works well for your setup, you can disable template translation using this filter since it cannot be done directly in Polylang when the setting is defined through wpml-config.xml:

add_filter('pll_get_post_types', function( $post_types, $is_settings ) {
    unset( $post_types[ 'bricks_template' ] );
    return $post_types;
}, 10, 2);

But it seems like the issue @HOSEIN is different since he had templates translation enabled already. Probably best to share temporary admin access to help@bricksbuilder.io so we can investigate :slight_smile: @HOSEIN please include a link to this forum thread as well as WAIT: Component / polylang issue in builder in your email so we can look into both.

1 Like

Hi @charaf,

I just sent it to the email. Thank you.

Instead of translating templates we should translate strings? Isnt it crazy to make a translation of template if it has 1 word that needs to be translated?

Agreed. It’s fine for smaller sites, but it gets tiring as you scale. That’s how our WPML integration works.

Hi @HOSEIN,

@aslotta was right, the issue on your site is also linked to the introduction of the wpml-config.xml file. The template & page settings are now being automatically copied whenever you save a template.

We’ll work on a fix to either disable this new behaviour or to automatically translate the post IDs.

In the meantime, you may use the following code to disable this behaviour:

/**
 * Remove _bricks_template_settings from copied meta fields in Polylang
 */
add_filter( 'pll_copy_post_metas', function( $metas, $sync, $original_post_id ) {
    // Remove _bricks_template_settings from the array of meta keys to copy
    $metas = array_diff( $metas, [ '_bricks_template_settings', '_bricks_page_settings' ] );
   
    return $metas;
}, 10, 3 );
1 Like

Hi everybody,

I have an issue on my multilingual site as I am not able to translate SEO metadata with Polylang installed. I’ve been advised by @timmse to direct my questions to this thread as the issue probably has the same root cause.

Here is my original post with a detailed breakdown of the issue. Basically, I edit the SEO on an English page to be in English, but it adds it to the Czech page as well, and if I try and change it there, it changes also on the English page. Bit of a pickle.

I can see from this thread that there is an issue with page settings being copied across translations, so presumably this includes the SEO. @charaf 's last reply offers a temporary workaround, but I am unfortunately not a developer and would appreciate a few pointers. Apologies if these are dumb questions :slight_smile:

Does the code need any modifications if I want to fix the SEO? Where exactly should I add it? In the wpml-config.xml file or somewhere else?

Thank you in advance!

Hi @tobias.tarcala,

Please add the code shared by Charaf in the function and see if the problem is resolved? Please share the result here. Thanks!

/**
 * Remove _bricks_template_settings from copied meta fields in Polylang
 */
add_filter( 'pll_copy_post_metas', function( $metas, $sync, $original_post_id ) {
    // Remove _bricks_template_settings from the array of meta keys to copy
    $metas = array_diff( $metas, [ '_bricks_template_settings', '_bricks_page_settings' ] );
   
    return $metas;
}, 10, 3 );

Hi @HOSEIN ,

I added the code to functions.php in the child theme but unfortunetaly it didn’t fix the issue. SEO stays the same across languages :face_with_diagonal_mouth:

1 Like

Thank you @tobias.tarcala,

I’m not sure if your problem is exactly the same as mine. But I also tested the code, it worked fine at first but now it doesn’t work anymore. That’s why I wanted you to try it too.

Thanks for the reply @HOSEIN,

What’s the best course of action then? Should I revert back to Bricks 1.12.5 for the meantime before this is fixed in 2.0.1? Or is there anything else I can try?

Hi @tobias.tarcala,

I’m not sure if your problem is exactly the same as what I reported here. Bricks 2.0 has different challenges with Polylang. I also see that the problem that existed here was fixed with version 2.0.1. So I suggest you go to 2.0.1 first to see if the problem still exists. If so, go back to 1.12.5 so that the problem can be fixed in future versions.

Hi @tobias.tarcala,

After adding the code snippet, you’ll need to use Bricks to edit the translated page and remove any meta descriptions that were previously added as a result of this bug. Once you delete or update the SEO settings, they should no longer automatically sync between pages. If you continue to experience issues, please provide screenshots or steps to reproduce the problem, as I am no longer able to replicate it locally with the code snippet applied.

Hello
Bricks 2.01. I have the same problem like @HOSEIN.

The problem is that Bricks 2.0 does not allow the individual condition in the templates to select two different pages. If we try to select two different pages, it will automatically be set to similar pages or the same blog pages.

Any help appreciated. Thanks

We’ve fixed this issue in Bricks 2.0.2 now available as a one-click update in your WordPress Dashboard.

Please take your time to read the changelog entry before updating: Bricks 2.0.2 Changelog – Bricks, and let us know if you continue to experience issues.

1 Like