Last active
March 6, 2020 18:03
-
-
Save kamalahmed/991e904a81cc61b78e294dffd6623713 to your computer and use it in GitHub Desktop.
You can increase your WordPress Site speed by removing extra information from wp head that you may not need.
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 | |
/** | |
* It removes unnecessary actions and filters to clean up the WP head to speed up | |
*/ | |
function prefix_clean_wp_head() { | |
// https://scotch.io/tutorials/removing-wordpress-header-junk | |
remove_action( 'wp_head', 'rsd_link' ); | |
remove_action( 'wp_head', 'wp_generator' ); | |
remove_action( 'wp_head', 'feed_links', 2 ); | |
remove_action( 'wp_head', 'feed_links_extra', 3 ); | |
remove_action( 'wp_head', 'wlwmanifest_link' ); | |
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); | |
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); | |
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); | |
// http://wordpress.stackexchange.com/a/185578/26817 | |
remove_action( 'admin_print_styles', 'print_emoji_styles' ); | |
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); | |
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); | |
remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); | |
remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); | |
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); | |
add_filter( 'emoji_svg_url', '__return_false' ); | |
add_filter( 'tiny_mce_plugins', 'rational_tiny_mce_plugins_clean' ); | |
// http://wordpress.stackexchange.com/a/211469/26817 | |
remove_action( 'wp_head', 'rest_output_link_wp_head' ); | |
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); | |
remove_action( 'template_redirect', 'rest_output_link_header', 11, 0 ); | |
} | |
add_action( 'init', 'prefix_clean_wp_head' ); | |
/** | |
* Filtering TinyMCE plugins | |
* | |
* @param array $plugins Array of TinyMCE plugins | |
* | |
* @return array Filtered array of TinyMCE plugins | |
*/ | |
function rational_tiny_mce_plugins( $plugins ) { | |
if ( is_array( $plugins ) ){ | |
return array_diff( $plugins, array( 'wpemoji' ) ); | |
}else{ | |
return []; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment