1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Clean up HTML |
4
|
|
|
* |
5
|
|
|
* @since: 1.0.0 |
6
|
|
|
* @author: sewmyheadon |
7
|
|
|
* @link: https://ivycat.com |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Remove WordPress Generator HTML comments |
13
|
|
|
*/ |
14
|
|
|
remove_action( 'wp_head', 'wp_generator' ); |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Remove WooCommerce Generator HTML comments. |
18
|
|
|
*/ |
19
|
|
|
remove_action( 'wp_head', 'wc_generator_tag' ); |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Remove All in One SEO Pack HTML comments |
23
|
|
|
* @link //gist.github.com/llgruff/a7ab776167aa0ed307ec445df54e5fdb |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
if ( defined( 'AIOSEOP_VERSION' ) ) { |
|
|
|
|
26
|
|
|
add_action( 'get_header', function () { |
27
|
|
|
ob_start( |
28
|
|
|
function ( $o ) { |
29
|
|
|
return preg_replace( '/\n?<.*?One SEO Pack.*?>/mi', '', $o ); |
30
|
|
|
} |
31
|
|
|
); |
32
|
|
|
} ); |
33
|
|
|
add_action( 'wp_head', function () { |
34
|
|
|
ob_end_flush(); |
35
|
|
|
}, 999 ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Remove Yoast SEO HTML comments |
40
|
|
|
* @link //gist.github.com/llgruff/a7ab776167aa0ed307ec445df54e5fdb |
41
|
|
|
* @link //gist.github.com/paulcollett/4c81c4f6eb85334ba076 |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
if ( defined( 'WPSEO_VERSION' ) ) { |
|
|
|
|
44
|
|
|
add_action( 'get_header', function () { |
45
|
|
|
ob_start( |
46
|
|
|
function ( $o ) { |
47
|
|
|
return preg_replace( '/^<!--.*?[Y]oast.*?-->$/mi', '', $o ); |
48
|
|
|
} |
49
|
|
|
); |
50
|
|
|
} ); |
51
|
|
|
add_action( 'wp_head', function () { |
52
|
|
|
ob_end_flush(); |
53
|
|
|
}, 999 ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Remove Google Analytics by MonsterInsights HTML comments |
58
|
|
|
* @link https://wordpress.org/plugins/remove-google-analytics-comments/ |
59
|
|
|
*/ |
60
|
|
|
function isgabmi_active( $plugin ) { |
61
|
|
|
$network_active = false; |
62
|
|
|
if ( is_multisite() ) { |
63
|
|
|
$plugins = get_site_option( 'active_sitewide_plugins' ); |
64
|
|
|
if ( isset( $plugins[ $plugin ] ) ) { |
65
|
|
|
$network_active = true; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return in_array( $plugin, get_option( 'active_plugins' ) ) || $network_active; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
View Code Duplication |
if ( isgabmi_active( 'google-analytics-for-wordpress/googleanalytics.php' ) || isgabmi_active( 'google-analytics-premium/googleanalytics.php' ) ) { |
|
|
|
|
73
|
|
|
add_action( 'get_header', function () { |
74
|
|
|
ob_start( function ( $o ) { |
75
|
|
|
return preg_replace( '/\n?<.*?monsterinsights.*?>/mi', '', $o ); |
76
|
|
|
} ); |
77
|
|
|
} ); |
78
|
|
|
add_action( 'wp_head', function () { |
79
|
|
|
ob_end_flush(); |
80
|
|
|
}, 999 ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.