
If you’re like me, you love Polylang!
I’ve used WPML in the past, and Polylang makes it look like an oversized overpowering slowpoke. What I hate the most about WPML is the fact that it is not “fully compatible” with Advanced Custom Fields, which is stupid to put it politely.
There is one problem with Polylang, however. Which is the fact that it does not copy the title and content when you create a new translation. I don’t fully agree with the reasoning behind this. There should at least be an option to copy the content from the original post to the translation.
But don’t worry, the fix is easy! Just add this in your theme’s functions.php file and the problem is fixed:
// Make sure Polylang copies the content when creating a translation function jb_editor_content( $content ) { // Polylang sets the 'from_post' parameter 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', 'jb_editor_content' );
Similarly, if you want to copy the title as well, use the following code:
// Make sure Polylang copies the title when creating a translation function jb_editor_title( $title ) { // Polylang sets the 'from_post' parameter 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', 'jb_editor_title' );
That works for the content, but not for the title. Can you add to your code to do the title too?
Hi Karen,
I see how that can be useful. I’ve updated the post. Good luck!
I also don’t agree with the reasoning behind this, so big thank you :o)
Hi,
This is exactly what I’m searching for but when I’ve added this to my WP, it broke down. It was just a white screen.
I’ve added your code to wp-includes/functions.php or should I add this to the function file from the theme?
I’m using Betheme on wp 4.1.7
Many thanks!
Hey, yeah it needs to go in your theme’s functions.php
Hi Junaid, Thanks for this.. It worked nicely. However I have some fields that are not translating. Like name of the person posting, location etc.. Any ideas?
Hi,
Custom fields should copy over quite nicely. If it doesn’t, then perhaps something else is wrong?
You have any idea what this can be?
Many thanks! The best and easiest way I’ve seen. However, it seems that when you publish the translation of a page, Polylang republishes the initial version as well… not the best for blogging!
I don’t think that’s how it works. You might want to double-check this.
Thanks a lot for the code. Working great. Do you have any idea how to make it work with ACF?
Hello Marek,
It fully supports ACF. When you make a new translation, it copies all the ACF fields correctly.
Hi Junaid,
Yes, you’re right. My fault. I’ve copied post without acf field 😉
Thanks a lot once again. It’s saved me a lot of time 🙂 Great piece of code 🙂
Hi,
Thanks! It works wel. Just one problem, it doesn’t copy my gallerys?
Excellent code, but would it be better if it included a an “if” clause to check if Polylang plugin is active ? In case not, disregard rest of code. In this way, we load the code selectively
Thank you
Hello,
I use a child theme and added the code you provided in the child theme’s functions.php, but I’m getting an internal server error.
If I add it to the parent theme functions.php, it would be removed if the theme is updated, wouldn’t it?
It should work fine in a child theme – you can try wrapping a “is_admin()” condition around the code
Really nice !!
Do you think we can make the same for all the custom we have in the original ? 🙂 :p
This is super usefull! thanks a lot!
I also miss this option in polylang…
Too bad we can’t copy content to existing translations…
Maybe one day 🙂
Hello,
I added this filter but it messed my posts a bit. Is there a way to remove it? I tried remove_filter( ‘default_content’, ‘jb_editor_content’ ); but it keeps copying the content. Thank you.
How about removing the code you added?
Hi!
It works but not tottally. Im using WP JOB MANAGER and when im trying to duplicate all content, all fields from this plugin are not beging copyed. How to copy this content too?
Also, some one knows how to autoduplicate in all languages when a post is published?
Thanks a lot!
Hi, this tutorial is just to copy the content for the default WordPress editor. I’d suggest contacting the plugin developer for what you need.
Hello,
This is working for me but the galery of media is not going along with it unfortunately,
Any solution for it
Cheers
This tutorial is only for the content. The Pro version of Polylang allows you to copy all the content.
Absolutely perfect and needed posting – thank you so much!
Works like a charm!
Thank you very much.
Thank you for this code. You rock!
Soooooo helpful!! Thanks a million.
Thank you! It works really fine, even with Visual Composer!
I can believe it works ! Thanks !
Boom. That worked great! Thanks. Yes this should be an option especially for those who use page builders.
It can be dangerous from an SEO point of view to possibly inherent text from the other language, but if you are careful this is a lot easier than recreating the page.
Thanks again.
Thank you, really!!!! this trick saved me!!!!
Hello the code that copies the title works fin for me, but the one that should copy the content dosn’t. Does it support woocommerce products ?
Thanks in advance!
Hey, this code is just to copy the content in the WordPress editor!
the wooCommerce short description is just a rebranding of the standard wordpress excerpt field so you can do it like this:
// Make sure Polylang copies the excerpt [woocommerce short description] when creating a translation
function hy_editor_excerpt( $excerpt ) {
// Polylang sets the ‘from_post’ parameter
if ( isset( $_GET[‘from_post’] ) ) {
$my_post = get_post( $_GET[‘from_post’] );
if ( $my_post )
return $my_post->post_excerpt;
}
return $content;
}
add_filter( ‘default_excerpt’, ‘hy_editor_excerpt’ );
hi,
i’ve added to theme files functions.php in last line this code and got an syntax error… where to add it?
Hi, the last line in functions.php should be fine. You can probably debug the syntax error?
awsome tip! thank you
It woooorked…yuhuuuu… you’re the man. Thanks a loooot!
Muchas gracias, me funcionó bien 😀
thanks a lot
the code works great
is it possible that you publish a code for copying the excerpt.
the woo commerce code didn’t work for me
thanks
guy
I love you!! Thanks for that!
Thank ou so much 🙂
I love you. thank you.
First of all thank you so Much for your work.
I have one question though, could it be possible, when I add posts in one language that the extension copies the post in another language automatically?
Don’t think Polylang does that 🙂
Wow!
This worked like magic. Thank you so much!!!
Works great however I have multiple pages and when I change from English to French for example and then go to another page the new pages is in English and not translated.how can I fix this?
Thanks a lot, very useful and it worked like a charm. Bravo.
Hi, your code works like charm but on my site the property meta information is not being copied/imported over into the new language, any code suggestions how I can also get this to happen smoothly?
Thanks in advance
Hey Sabrina,
This is only to copy the content. I think the Pro version of Polylang should copy over the fields.
Amazing! Exactly what I have been looking for! It even copies content for other post types, for example Portfolio entry. Great work, mate.