Last active
October 25, 2021 16:42
-
-
Save guydumais/21b00532068a1ff2318706e146d76665 to your computer and use it in GitHub Desktop.
WordPress ➧ Change Locale Dynamically in WordPress
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
/** | |
* Change Locale Dynamically in WordPress. | |
* | |
* @author Guy Dumais. | |
* @link https://en.guydumais.digital/change-locale-dynamically-in-wordpress/ | |
*/ | |
// Filters all language attributes in the html tag. | |
add_filter( 'language_attributes', $af = function( $output, $doctype ) { | |
if ( strpos($output, 'en-US') !== false ) { | |
$output = str_replace('en-US', 'en-CA', $output); | |
} | |
return $output; | |
}, 10, 2 ); | |
unset( $af ); | |
// Filters all language attributes in social tags (og:). | |
add_filter( 'locale', $af = function( $locale ) { | |
if( 'en_US' == $locale ) { | |
$locale = 'en_CA'; | |
} | |
return $locale; | |
}, 10 ); | |
unset( $af ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment