Remove unnecessary scripts

Whether you’re building a new theme from scratch, or using this post to streamline your existing one, I’d recommend reviewing the following functions and applying those that apply:

Limit Post Revisions

More of a good house-keeping tip, i’d recommend limiting the revision history of your posts. By default, WordPress will keep an infinite number of revisions which builds up over time and can bloat the database. You can limit the number of revisions for posts (say to 3) by adding the following line to your wp-config file.

define( ‘WP_POST_REVISIONS’, 3 );

Remove Emoji Support

By default, Emojis are enabled on your WordPress installation. If don’t want to use Emojis on your posts and comments, we can remove the script and stylesheet that are called into your theme. Simply add the following two lines to your theme’s functions.php file:

remove_action( 'wp_head', 'print_emoji_detection_script', 7 );

remove_action( 'wp_print_styles', 'print_emoji_styles' );

Remove the Comment Reply Script

If you’re not using the built-in post commenting system, or if you’re using a better platform like DISQUS, you can remove the redundant comment script. In the first instance, remove where it’s initially being enqueued on your theme’s functions.php file. If you can’t find it, add the following code to your functions.php:

function remove_comment_reply_script(){

wp_deregister_script( 'comment-reply' );

}

add_action('init','remove_comment_reply_script');

Remove Query Strings for static resources

A lot of page-speed analysis tools will pull you up on having unnecessary query strings when you call scripts and styles into your theme. You can solve this for all instances, by adding the following function to your functions.php:

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 );

Remove oEmbed Scripts

Since WordPress 4.4, oEmbed is installed and available by default. WordPress assumes you’ll want to easily embed media like tweets and YouTube videos so includes the scripts as standard. If you don’t need oEmbed, you can remove it by installing this accredited plugin or by adding the following function to functions.php: