Last active
September 17, 2019 09:35
-
-
Save 2ndkauboy/76d5c5a14df8c0d01d81743880e0e386 to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* Language Attribute Variant Fix | |
* | |
* @package language-attributes-variant-fix | |
* @author Bernhard Kau | |
* @license GPLv3 | |
* | |
* @wordpress-plugin | |
* Plugin Name: Language Attribute Variant Fix | |
* Plugin URI: https://kau-boys.de | |
* Description: Removes the language variant from the laguage attribute used on the HTML root element | |
* Version: 0.1 | |
* Author: Bernhard Kau | |
* Author URI: https://kau-boys.de | |
* License: GPLv3 | |
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt | |
*/ | |
/** | |
* Strips the language variant | |
* | |
* @param string $language_attributes The original language attributes value. | |
* | |
* @return string | |
*/ | |
function language_attributes_variant_fix( $language_attributes ) { | |
return preg_replace( '/lang="([\w]+-[\w]+)-[\w]+"/', 'lang="$1"', $language_attributes ); | |
} | |
add_filter( 'language_attributes', 'language_attributes_variant_fix' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If we change the quantifier for the last segment, the function will work with
de-DE
als well asde-DE-formal
.I also selected the country code only, following the conversation on Twitter.