Created
July 25, 2024 12:02
-
-
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.
This file contains hidden or 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
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