Last active
October 7, 2021 14:03
-
-
Save itsHall/506a7ad3e81abfd13a2fb74e3ef365bc to your computer and use it in GitHub Desktop.
Remove Unused hreflang Tags | WPML
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 | |
function remove_unneeded_hreflang( $hreflang_items ){ | |
global $post; | |
global $sitepress; | |
$t_post_id = $sitepress->get_element_trid( $post->ID, 'post_page' ); | |
$translations = $sitepress->get_element_translations($t_post_id, 'post_page', false, true); | |
if(count($translations)==1){ | |
unset($hreflang_items['es']); | |
return $hreflang_items; | |
} | |
return $hreflang_items; | |
} | |
add_filter( 'wpml_hreflangs', 'remove_unneeded_hreflang' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment