How to translate layouts?

How can specific elements of a layout be translated? The website is running with WPML.

  1. it’s about the title of the blog page: “News”, “Nouvelles” or “Novedades”. Can’t find a dynamic content for the h1 tag. {{dc:post:title}} returns the title of the first (and only post so far).

  2. and the “Read more”-Button text that should be translated to French and Spanish.

Best regards

For the first part (title of the blog page) I found a solution inspired by the shortcode solution for a previous question from me.

By adding the following to the functions.php of the child theme I just have to add the shortcode where I want it and it works.

function display_page_title() {
return get_the_title(get_option(‘page_for_posts’, true));
}
add_shortcode(‘page_title’, ‘display_page_title’);

Credits go to https://wpscholar.com/blog/get-title-for-posts-page-in-wordpress/

For the second problem I also found a solution, but it’s a bit annoying to keep track of it for every new post.

I’ve added a custom field to each post in each language:

Name: read_more
Value: Read more (or “Lire la suite” or “Lee mas” depending on the language of the post)

At the “Read more”- button at the blog layout I used {{dc:post:meta key=“read_more”}} for the Primary Text of the button.

That works, but would be nice to automate it somehow without the need to add the custom field each time a new post is written. :slight_smile:

Edit: Using ACF it is at least possible to add the custom field on top of each the post when adding/editing a post and make it mandatory. That way an editor can’t forget to enter the right value.

Hello @mircotripoczky,

Thanks for writing in! Just for future topics, self responding or bumping your post pushes it back in our Queue system so it takes longer to respond to.

It’s good to know that you have found a solution to your issue. By the way, if you are using WPML, you should be able to translate your custom layout. Please check out this documentation:

Best Regards.

Thanks for your explanation. Didn’t mean to push my post back into the queue, just wanted to share my findings.

I used to use string translations by WPML and also string replacement via functions.php, but it this case it won’t work I fear because it’s about translating elements of a layouts that I added (like a custom “read more” button) and those are not part of any .po-file e.g. or can’t be found by the string translation plugin.

An easy way for us users – but probably not for your developers – would be to make the little flag icons at the bottom right – which work great for other content – functional for layouts. Right now they are just shown but only result in an error message: “Failed to create Layout”. Don’t know if that’s even possible within Wordpress to use different templates/layouts for different languages. Since I work on a lot of multi lingual websites, that would be very very helpful :slight_smile:

Best regards
Mirco

Hi Mirco,

Thanks for the feedback. I will pass this thread on to our developers. They have something in mind that will help.

Cheers.

Hi @mircotripoczky,

Thanks for sharing your insights here. I’m going to issue a bug report so we can look into why it says “Failed to create Layout”. Those should be translatable like Headers and Footers.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.