Created
March 30, 2022 21:00
-
-
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.
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 | |
/** | |
* 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