reduce

Reduce HTTP Requests in WordPress

WordPress can be fickle when trying to speed it up, especially if you are using more than a handful of plugins. So to help with the performance we can reduce some requests by disabling some things in WordPress that we may not be using.

Disable Emoji’s

If you’re not using emoji’s on your site then lets not load them and reduce an HTTP request. Add the code below to your functions file.

/** 
* Disable the emoji's
*/
function disable_emojis() {
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_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
}
add_action( 'init', 'disable_emojis' );

/**
* Filter function used to remove the tinymce emoji plugin.
*/
function disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}


Remove Embed

The embed script simply auto formats pasted content in the editor like videos or tweets, so if you do have a use for this leave this out. Add the code below to your functions file.

// Remove WP embed script
function speed_stop_loading_wp_embed() {
if (!is_admin()) {
wp_deregister_script('wp-embed');
}
}
add_action('init', 'speed_stop_loading_wp_embed');

Remove Query Strings

Most often scripts in WordPress will end in a number, this number is their version number (ver=1.1.2). This can prevent the scripts from caching so lets just remove them. Add the code below to your functions file.

/**
* Remove Query Strings
*/
function _remove_script_version( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

Happy Coding!