-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml-global-lang-attribute.php
61 lines (47 loc) · 1.62 KB
/
html-global-lang-attribute.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* Plugin Name: HTML Global lang Attribute
* Plugin URI: https://github.com/reatlat/wp-html-global-lang-attribute
* Description: This plugin slice the language attribute for HTML tag, For example: lang="en-US" to lang="en"
* Tags: lang, language, slice, seo
* Version: 1.0.5
* Author: Alex Zappa
* Author URI: https://alex.zappa.dev/
* Donate link: https://www.paypal.me/reatlat/5usd
* Requires at least: 2.1.0
* Tested up to: 6.1
* Requires PHP: 5.6
* Stable tag: 1.0.5
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Text Domain: html-global-lang-attribute
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) )
{
die;
}
function activate_htmlGlobalLangAttribute()
{
// TODO: activate hooks
}
function deactivate_htmlGlobalLangAttribute()
{
// TODO: deactivate hooks
}
register_activation_hook( __FILE__, 'activate_htmlGlobalLangAttribute' );
register_deactivation_hook( __FILE__, 'deactivate_htmlGlobalLangAttribute' );
if ( ! function_exists( 'set_HtmlGlobalLangAttribute' ) )
{
function set_HtmlGlobalLangAttribute( $output )
{
$lang = substr( get_locale(), 0, 2);
if ( preg_match( '#lang="[a-z-]+"#i', $output ) ) {
// TODO: if ( strrpos ( $output , 'en-US' ) ) { ... }
$output = preg_replace( '#lang="([a-z-]+)"#i', 'lang="' . $lang . '"', $output );
}
return $output;
}
add_filter( 'language_attributes', 'set_HtmlGlobalLangAttribute');
}