Skip to content

[WordPress] Automatically Copy the Main Language Article Content When Writing Different Language Article via Polylang

Last Updated on 2021-10-19 by Clay

For a long time, I have used the famous Polylang plugin in WordPress to create website content in different languages of Chinese and English.

For practicing my translation skill, I usually write article in Chinese first, and then open the articles to write English version.

So I often copy Chinese content into English articles, and then translate them sentence by sentence.

But recently, due to surgery, recuperating at home and being very leisurely, the number of writing articles has increased, I found it is tired to copy the articles from Chinese to English.

I heard that the Polylang Pro version already supports automatically copy the source article when opening a new article in other languages, but in fact, according to the Make Polylang WordPress plugin copy the content from the original post, we can do the same.


Copy Method

Go to the WordPress backend, find the file functions.php and edit it. My path is public_html/wp_content/themes/neve/functions.php, but my theme is Neve, so you need to replace it to your theme name.

Add the following code at the functions.php file bottom:

// Polylang
// 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' );


// 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' );


jb_editor_content() copy the source article’s content;

jb_editor_title() copy the source article’s title.


References


Read More

Tags:

Leave a ReplyCancel reply

Exit mobile version