Copying the content of the original publication using the Polylang plugin

 
Copying the content of the original publication using the Polylang plugin
Copying the content of the original publication using the Polylang plugin

If you use the free version of the Polylang for WordPress, you already know that the new page or post it generates for translation does not copy the original content

This is one of the features of its paid version and in the free version you have to paste it by hand.

To solve this and speed up the process, just add some functions in the functions.php file of your template.

It is always advisable to add it in a “child theme“in your own functions plugin or using Code Snippets in case it doesn’t work in your case or in case something breaks due to a future update of WordPress, your template, Polylang or PHP version.

// Copy content when creating a translation with Polylang
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' );

// Copy content when creating a translation with Polylang
function jb_editor_title( $title ) {
// Polylang sets the parameter 'from_post'
 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' );

I don’t know if it works on all templates (here it works fine with GeneratePress). I found it in a note from December last year, so it’s best to try it first in an isolated test environment (staging).

Translating tags with Polylang, another story

A side note. Polylang, despite being one of the most popular and light-weight free plugins for creating a multilingual blog is one of the few that I use that I think does not improve too much in its PRO version and needs to evolve to simplify its use, improve the translation of strings and make it more intuitive.

Now that we can copy the original content with Polylang to the new page to be translated, we will have the title, the content and normally also the tags

The problem here in the case of the posts is that the tags are copied in Spanish and then saved as new ones, adding the language prefix at the end of the slug, for example “nombredeetiqueta-en” (in the case of English).

Copying the content of the original publication using the Polylang plugin

This results in the creation of yet another new tag with no link to the original language tag and no translation. It will most likely end up orphaned or used in a single post

Worse, they will pile up to laughable numbers. Believe me, before the last revision and cleaning (which you have to do very carefully if you index them in the robots.txt and create 301 redirects because they are URL’s of your page that will be broken) they added up to the bulky figure of 8848

In addition, having too many tags slows down database queries and hurts performance.

The solution is not to remove them in the editor and add new ones in the new language because that won’t make them get deleted, you will just be creating again the same words with the“-en” prefix in the slug.

The ideal way, although tedious, is to be clear about which tags (four or five at most) you are going to use exactly in the post to translate and CREATE BEFORE their corresponding translations

Copying the content of the original publication using the Polylang plugin

Once the translations are saved, when you create the new copy of the post, Polylang will also export the tags, but now translated for the corresponding chosen language.

The tags serve primarily to improve internal searches on your blog and although many SEO experts advise not to index neither tags nor categories, if done with a rational and careful strategy, they can generate a not inconsiderable amount of organic visits. I can vouch for this.

You can get a lot out of tags by creating good descriptions and a logical hierarchy that does not overlap the names of the categories and avoiding the creation of content that could be considered duplicate.


Suscríbete por email para recibir las viñetas y los artículos completos y sin publicidad

1 thought on “Copying the content of the original publication using the Polylang plugin”

Comments are closed.