Created
January 29, 2016 11:06
-
-
Save anonymous/7773a69d19a29429a96c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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