Polylang – Duplicating content from original post across translations
This post can be helpful for anybody using Polyang plugin to handle translations.
Working on original content (text, medias) is a time saver for translation work; but in the free version of Polylang, you can’t duplicate content or title from original post across translation. This lack always pop up when comparing polylang with WPML.
Trying to solve this problem, i came across a post wrote in english by Junaid Bhura who wrote a code snippet allowing to duplicate content and title from posts you want to translate with Polylang.
To add this additionnal code, you’d better use a child theme (if you don’t know how to create one, a very simple tutorial is available by following this link.)
To duplicate original post content, add the following code snippet to functions.php file of your child theme :
// Duplicate post content from original across translation function cw2b_content_copy( $content ) { if ( isset( $_GET['from_post'] ) ) { $my_post = get_post( $_GET['from_post'] ); if ( $my_post ) return $my_post->post_content; } return $content; } add_filter( 'default_content', 'cw2b_content_copy' );
if you also want to duplicate post title, add the following code snippet to functions.php file of your child theme :
// Duplicate post title from original across translation function cw2b_editor_title( $title ) { if ( isset( $_GET['from_post'] ) ) { $my_post = get_post( $_GET['from_post'] ); if ( $my_post ) return $my_post->post_title; } return $title; } add_filter( 'default_title', 'cw2b_editor_title' );
For Divi theme users, when you’ll add a translation, you will see a lot of shortcodes inside the wordpress editor.
You just have to click on “Use The Divi Builder” to activate it and see your content as sections, rows, columns and modules”
Feel free to comment and ask for help if needed.
Can I also copy the date?
Sorry i don’t know
Fantasctic, works with guttenberg. Thanks, so much! I was using with snippets plugin…
Hello and thank you for the help.
I understand well: it doesn’t not work for pages created via Divi Builder ? Onyl for posts ?
est-ce que ça marche aussi avec les “pages” ou seulement avec les “posts”?
j’ai implémenté le code dans le fichiers functions de mon theme divi, mais sans résultat.
j’ai un site simple, vitrine, avec une seule page qui renferme beaucoup de contenu que j’aimerais proposer aussi dans une autre langue. Je ne sais pas comment procéder avec polylang pour copier le contenu de ma page mère en celui de la page traduite.
Je confirme : ça marche toujours à ce jour 🙂
Toutefois, il faut installer le plugin “Classic Editor” comme dit plus haut, effectivement avec Gutemberg ça ne fonctionne pas.
Merci à vous pour ce bout de code très utile !
Vincent
Marche pas pour moi non plus, j’utilise aussi Woocommerce sur mon site.
Dommage ça paraissait magique !
Hello friends, it did not work for me but I installed the classic editor plugin and the code worked, it works with the classic editor not with the new gutenberg, I hope it helps.
Hi,
It is simple as that; no plugin is required.
One question, I have other fields like phone, email, website, Google mape, Author, etc. How can I make them duplicated too?
Cheers
Thank you it worked! Much karma for you
Title is copied, but when i want to edit the page with Divi, it’s still a blank page and there are no other pages of my website displayed when i try to “clone existing page”. Guess i’ll have to do a lot of copying to do this :/ Thank you still for the code
Bonjour,
Vos codes ne fonctionnent pas 🙁
J’ai pourtant intaller un thème enfant, copier coller les codes ds functions.php mais cela ne va.
Bonjour, pourtant je les utilise sur plusieurs sites et ils fonctionnent. Désolé que ça ne marche pas pour vous 🙂
Not working for me 🙁
Hi Fabrice :D.
You’re a life saver :D!! The plugin “Duplicate post” was not working correctly when I had to duplicate Divi page, so your great tips is a really really cool and a must have “child functions” features !!
Thanks a lot for sharing your code with us :D!!
Pierre.
Thanks a lot for your feedback Pierre