Skip to content

Instantly share code, notes, and snippets.

@itsHall
Last active October 7, 2021 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsHall/506a7ad3e81abfd13a2fb74e3ef365bc to your computer and use it in GitHub Desktop.
Save itsHall/506a7ad3e81abfd13a2fb74e3ef365bc to your computer and use it in GitHub Desktop.
Remove Unused hreflang Tags | WPML
<?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