Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thecancerus/7ea209660750a7a7d524e0fd8027d4c9 to your computer and use it in GitHub Desktop.
Save thecancerus/7ea209660750a7a7d524e0fd8027d4c9 to your computer and use it in GitHub Desktop.
add the following code in functions.php file of monomyth theme to fix the hreflang urls issue for polylang plugin.
add_filter( 'pll_rel_hreflang_attributes', function( $hreflangs ) {
$app_slug=aw2_library::get('app.slug');
if($app_slug == 'root') return $hreflangs;
$default_lang = pll_default_language();
$hreflangs_new = array();
foreach($hreflangs as $key=>$url){
$url_slug = site_url().'/'.$key;
if($key == $default_lang){
$url_slug = site_url();
}
$hreflangs_new[$key] = str_replace( $url_slug, $url_slug.'/'.$app_slug, $url );
}
//loop through the array and replace the
return $hreflangs_new;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment