Skip Navigation

[Resolved] Use a custom post layout on the second language (WPML)

This support ticket is created 5 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 15 replies, has 2 voices.

Last updated by cristianoT 5 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1366049

Hello I have a custom post type: "Raccomandazioni Professionista"
I have created the layout and it works correctly.
I now added the second language (english) with WPML and when I open a Raccomandazione Professionista type post it do not use the layout I made.
How can I extend the layout of the forst language (italian) to the second (english)?

Thanks

#1366311

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can switch the different layout on fly using the Layout hook: get_layout_id_for_render

For example:

add_filter('get_layout_id_for_render', 'func_assign_layout_by_language', 10, 2);
function func_assign_layout_by_language( $id, $layout ){
        global $post;
        
        $current_language = apply_filters( 'wpml_current_language', NULL );
         
 
        if(   $current_language ==  'en' && $post->post_type === 'raccomandazioni-professionista' ){
            return 99999;
        }
 
        return $id;
    }

Where:
- Replace 99999 with your english language layout ID you want to assign
- Replace post type slug if needed.

More info:
=> https://wpml.org/wpml-hook/wpml_current_language/

#1366463

Actually it not worked...
I added the snippet you wrote in the function.php...

ita version
hidden link

en version
hidden link

#1367059

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

That is really strange. Can you please share access details and tell me what Layout you want to use with English language and for another language.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1367177

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sorry but Can you please tell me what layout you want to display with IT language version post and what layout you want to display with En language version post.

#1367179

Sorry,
I want to show the same layout on raccomandazioni-prof for both language.

In italian it works fine:
hidden link

In english don't...

#1367183

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - so you want to assign the same layout.

If you check the following layout which is already assigned to "italian" language.
hidden link

*** Please make a FULL BACKUP of your database***
At the bottom of the above layout - you will see the button "Use this layout for 235 Raccomandazioni professionista " what if you click on that?

#1367317

I cannot see the button you are talking about...

#1367353

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

That is strange.

With the following link you should find that button on the bottom of the page;
=> hidden link

Can you please check the following screenshot: hidden link

Do you see it?

#1367373
2019-10-23_120122.jpg

Sorry, but this is what I see

#1367387

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - I do not know why.

Ok - there is another way as well.

*** Please make a FULL BACKUP of your database***
Click on the button "Change how this layout is used" and checkmark the checkbox "Aggiorna tutto per usare questo layout" and click on the Update button.

Please see the following screenshot: hidden link

Basically, by doing this, it will assign the "Layout for Raccomandazioni professionista" layout to all your existing posts of post type "Raccomandazioni professionista".

#1367473

I'm really sorry but nothing changed...
Maybe I have something wrong with the WPML configuration?

#1367475

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please confirm you took database backup and I will try to perform the action from this end.

#1367485

Go ahead I have done it (FTP and DB)

thanks

#1367493

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - I've performed the action and I can see now with EN language post the layout is assigned:
=> hidden link