1 | <?php |
||
2 | /** |
||
3 | * Custom functions that act independently of the theme templates |
||
4 | * |
||
5 | * Eventually, some of the functionality here could be replaced by core features. |
||
6 | * |
||
7 | * @package WordPress |
||
8 | * @subpackage Strip |
||
9 | */ |
||
10 | |||
11 | /** |
||
12 | * Adds custom classes to the array of body classes. |
||
13 | * |
||
14 | * @param array $classes group-blog. |
||
15 | * @return array |
||
16 | */ |
||
17 | function strip_body_classes( $classes ) { |
||
18 | // Adds a class of group-blog to blogs with more than 1 published author. |
||
19 | if ( is_multi_author() ) { |
||
20 | $classes[] = 'group-blog'; |
||
21 | } |
||
22 | |||
23 | return $classes; |
||
24 | } |
||
25 | add_filter( 'body_class', 'strip_body_classes' ); |
||
26 | |||
27 | /** |
||
28 | * Disable emojis introduced in WordPress 4.2. |
||
29 | */ |
||
30 | function disable_emojis() { |
||
31 | remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); |
||
32 | remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
||
33 | remove_action( 'wp_print_styles', 'print_emoji_styles' ); |
||
34 | remove_action( 'admin_print_styles', 'print_emoji_styles' ); |
||
35 | remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); |
||
36 | remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); |
||
37 | remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); |
||
38 | add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' ); |
||
39 | add_filter( 'wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2 ); |
||
40 | } add_action( 'init', 'disable_emojis' ); |
||
41 | |||
42 | /** |
||
43 | * Filter function used to remove the tinymce emoji plugin. |
||
44 | * |
||
45 | * @param array $plugins disable_emojis_tinymce. |
||
46 | * @return array Difference betwen the two arrays. |
||
47 | */ |
||
48 | function disable_emojis_tinymce( $plugins ) { |
||
49 | if ( is_array( $plugins ) ) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
50 | return array_diff( $plugins, array( 'wpemoji' ) ); |
||
51 | } return array(); |
||
52 | } |
||
53 | /** |
||
54 | * Remove emoji CDN hostname from DNS prefetching hints. |
||
55 | * |
||
56 | * @param array $urls URLs to print for resource hints. |
||
57 | * @param string $relation_type The relation type the URLs are printed for. |
||
58 | * @return array Difference betwen the two arrays. |
||
59 | */ |
||
60 | function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) { |
||
61 | if ( 'dns-prefetch' !== $relation_type ) { /** This filter is documented in wp-includes/formatting.php */ |
||
62 | $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' ); |
||
63 | $urls = array_diff( $urls, array( $emoji_svg_url ) ); |
||
64 | } |
||
65 | return $urls; } |
||
66 | |||
67 | /** |
||
68 | * Clean wp_head, remove queries. |
||
69 | * |
||
70 | * @since 1.1.3 |
||
71 | * @link: http://cubiq.org/clean-up-and-optimize-wordpress-for-your-next-theme |
||
72 | */ |
||
73 | remove_action( 'wp_head', 'wp_generator' ); // WP Version. |
||
74 | remove_action( 'wp_head', 'wlwmanifest_link' ); |
||
75 | remove_action( 'wp_head', 'rsd_link' ); |
||
76 | remove_action( 'wp_head', 'rel_canonical', 10, 0 ); |
||
77 | remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); |
||
78 | |||
79 | remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );// Parent rel link. |
||
80 | remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // Start post rel link. |
||
81 | remove_action( 'wp_head', 'index_rel_link' ); |
||
82 | |||
83 | remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Adjacent post rel link. |
||
84 | |||
85 | add_filter( 'the_generator', '__return_false' ); |
||
86 | |||
87 | remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); |
||
88 | remove_action( 'wp_print_styles', 'print_emoji_styles' ); |
||
89 | /** |
||
90 | * Cleanup head remove rss version |
||
91 | * |
||
92 | * @since 1.1.3 |
||
93 | */ |
||
94 | function strip_remove_rss_version() { |
||
95 | return ''; |
||
96 | } |
||
97 | /** |
||
98 | * Cleanup head remove X-Pingback |
||
99 | * |
||
100 | * @param array $headers remove x pingback. |
||
101 | * @since 1.1.3 |
||
102 | */ |
||
103 | function strip_remove_x_pingback( $headers ) { |
||
104 | unset( $headers['X-Pingback'] ); |
||
105 | return $headers; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Cleanup head remove inline CSS comments |
||
110 | * |
||
111 | * @since 1.1.3 |
||
112 | */ |
||
113 | function strip_remove_comments_inline_styles() { |
||
114 | global $wp_widget_factory; |
||
115 | if ( has_filter( 'wp_head', 'wp_widget_recent_comments_style' ) ) { |
||
116 | remove_filter( 'wp_head', 'wp_widget_recent_comments_style' ); |
||
117 | } |
||
118 | |||
119 | remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) ); |
||
120 | } |
||
121 |