Skip to content

Instantly share code, notes, and snippets.

@bavington
Last active October 1, 2020 10:15
Show Gist options
  • Save bavington/4b1231c35fd3db88acb0d4db2edb594f to your computer and use it in GitHub Desktop.
Save bavington/4b1231c35fd3db88acb0d4db2edb594f to your computer and use it in GitHub Desktop.
WordPress functions to remove (potentially) redundant functionality and page speed improvements.
<?php
// REMOVE EMOJIS
// Emojis are enabled by default, so if you don't want to use these you can remove the script and stylesheet:
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
// REMOVE COMMENT-REPLY.MIN.JS
// This is added by default to the footer, if you're not using post comments or DISQUS you can remove the script:
function remove_comment_reply_script(){
wp_deregister_script( 'comment-reply' );
}
add_action('init','remove_comment_reply_script');
// Remove WP embed script
// Removal of URL embedding for tweets, YouTube videos etc on the front-end
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 from static resources
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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment