Last active
February 18, 2021 16:31
-
-
Save flyingwebie/a29883832be8923bd17bfcc0a0a28a3c to your computer and use it in GitHub Desktop.
Custom attrs hreflang "x-default" Polylang
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
/* --------------------------------------------------------------------------- | |
* Set hreflang="x-default" according to Google content guidelines with Polylang | |
* --------------------------------------------------------------------------- */ | |
function filter_pll_rel_hreflang_attributes( $hreflangs ) { | |
foreach ( $hreflangs as $lang => $url ) { | |
if ( $lang === 'en' ) { | |
printf( '<link rel="alternate" href="%s" hreflang="%s" />' . "\n", esc_url( $url ), esc_attr( 'x-default' ) ); | |
} | |
} | |
return $hreflangs; | |
} | |
add_filter( 'pll_rel_hreflang_attributes', 'filter_pll_rel_hreflang_attributes', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment