Skip to content

Instantly share code, notes, and snippets.

Created January 29, 2016 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/7773a69d19a29429a96c to your computer and use it in GitHub Desktop.
Save anonymous/7773a69d19a29429a96c to your computer and use it in GitHub Desktop.
<?php
//Add this to your theme functions.php
function wpml_the_content_filter( $content ) {
global $post, $sitepress;
$element_type = 'post_' . $post->post_type;
$trid = $sitepress->get_element_trid( $post->ID, 'post_' . $post->post_type );
$element_translations = apply_filters( 'wpml_get_element_translations', null, $trid, $element_type );
$translation_type = apply_filters( 'wpml_element_translation_type', null, $post->ID, $post->post_type );
if ( WPML_ELEMENT_IS_NOT_TRANSLATED !== $translation_type ) {
$translations = '';
$duplicates = '';
if ( 0 < count( $element_translations ) ) {
foreach ( $element_translations as $language_code => $element_translation ) {
if ( (int)$element_translation->element_id !== $post->ID ) {
$element_translation_type = apply_filters( 'wpml_element_translation_type', null, $element_translation->element_id, $post->post_type );
if ( WPML_ELEMENT_IS_TRANSLATED === $element_translation_type ) {
$translations .= '<li>' . $language_code . '</li>';
}
if ( WPML_ELEMENT_IS_A_DUPLICATE === $element_translation_type ) {
$duplicates .= '<li>' . $language_code . '</li>';
}
}
}
}
if ( '' !== $translations ) {
$content .= '<p>This post is also available in: </p>';
$content .= '<ul>';
$content .= $translations;
$content .= '</ul>';
}
if ( '' !== $duplicates ) {
$content .= '<p>This post is duplicated in: </p>';
$content .= '<ul>';
$content .= $duplicates;
$content .= '</ul>';
}
}
return $content;
}
add_filter( 'the_content', 'wpml_the_content_filter' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment