Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joshuadavidnelson/32b0c6ff9ef051ed383350d734072d49 to your computer and use it in GitHub Desktop.
Save joshuadavidnelson/32b0c6ff9ef051ed383350d734072d49 to your computer and use it in GitHub Desktop.
Filter the hreflang urls and remove any that are indicative of draft or otherwise non-published content. Assumes that linked translations that are not yet published will show up as /?p=123 instead of pretty permalink.
<?php
/**
* Filter the hreflang urls and remove any that are indicative of draft or otherwise non-published content.
*
* Linked translations that are not yet published will show up as /?p=123 instead of pretty permalink.
*
* @param array $urls the array of language => url hreflang urls.
* @return array
*/
add_filter( 'multilingualpress.hreflang_translations', 'filter_mlp_hreflang_translations' );
function filter_mlp_hreflang_translations( $urls ) {
foreach ( $urls as $lang => $url ) {
if ( false !== strpos( $url, '?p=' ) ) {
unset( $urls[ $lang ] );
}
}
return $urls;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment