워드프레스에서 WPML 플러그인을 사용하면 영어, 중국어, 일본어 등 다국어 사이트를 운영할 수 있습니다. 워드프레스를 추가로 설치하지 않고 다국어로 운영하려는 경우에 유용할 수 있습니다.
WPML에서는 모든 콘텐츠를 일괄적으로 다른 언어로 복제할 수 있습니다.
그리고 글을 발행할 때 다른 언어로 글을 복제하는 것도 가능합니다. WPML을 사용한 워드프레스 사이트에서 글을 공개할 때 다른 언어(예: 영어, 중국어, 일본어 등)로도 글이 복사되어 공개되도록 하려면 경우 다음 코드를 사용 중인 워드프레스 테마의 함수 파일(functions.php)에 추가하도록 합니다.
// 글 발행 시 다른 언어로 자동으로 글 복제하기 // WPML - Auto duplicate of posts on publishing add_action( 'wp_insert_post', 'my_duplicate_on_publishh' ); function my_duplicate_on_publishh( $post_id ) { $post = get_post( $post_id ); // don't save for autosave if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } // dont save for revisions if ( isset( $post->post_type ) && $post->post_type == 'revision' ) { return $post_id; } // we need this to avoid recursion see add_action at the end remove_action( 'wp_insert_post', 'my_duplicate_on_publishh' ); // make duplicates if the post being saved // #1. itself is not a duplicate of another or // #2. does not already have translations $is_translated = apply_filters( 'wpml_element_has_translations', '', $post_id, $post->post_type ); if ( !$is_translated ) { do_action( 'wpml_admin_make_post_duplicates', $post_id ); } // must hook again - see remove_action further up add_action( 'wp_insert_post', 'my_duplicate_on_publishh' ); }
위 코드를 가급적 차일드 테마 내의 함수 파일에 추가하시기 바랍니다. 그렇지 않으면 테마가 업데이트될 때 변경 사항이 사라지게 됩니다.
특정 커스텀 포스트 타입 글만 복제하려면 조건을 추가하면 될 것입니다.
if ( 'portfolio' == get_post_type( $post ) ) { $post = get_post( $post_id ); .... }
위 코드를 테스트해보니 잘 작동하네요. 그림과 같이 한국어로 글을 작성하여 공개하면 영어, 일본어 등 다른 언어로도 글이 복제되어 공개됩니다.
이 방법을 사용하면 다른 언어로 일일이 글을 복제할 필요 없이 곧바로 글이 복사됩니다. 그러면 각 언어별로 번역할 수 있습니다.
참고로 자동으로 번역되도록 하려면 GTranslate를 이용해볼 수 있습니다. 하지만 번역 품질이 그리 만족스럽지 않을 수 있습니다.
댓글 남기기