Skip to content

Instantly share code, notes, and snippets.

@flyingwebie
Last active February 18, 2021 16:31
Show Gist options
  • Save flyingwebie/a29883832be8923bd17bfcc0a0a28a3c to your computer and use it in GitHub Desktop.
Save flyingwebie/a29883832be8923bd17bfcc0a0a28a3c to your computer and use it in GitHub Desktop.
Custom attrs hreflang "x-default" Polylang
/* ---------------------------------------------------------------------------
* 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