WPML Snippet: Duplicate post/page on publish


Notice: A non well formed numeric value encountered in /home/wiseguys/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/wiseguys/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/wiseguys/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/wiseguys/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

On the recent project, I had the requirement on making the duplicate with the same content of post base on the current post. If you have used plugin WPML, when you want to translate the post with “duplicate” checked.

For better explanation, you can look at the following image

WPML Snippet: Duplicate post/page on publish

I’m kind of lazy boy so I would like to create the new translation of current post to German automatically, so the new snippet is invented.

After looking around I got a hook can help us to achieve that. Here he is:

I will combine it with publish_post hook. The snippet below will contain all the comment mark so just read it, you will understand.

If you want to know how to use this snippet, please refer to this article. With WPML and especially on this WPML hook, you can do much more things than just auto duplicate, such as auto-translate!

 

Leave A Comment

Your email address will not be published. Required fields are marked *