WordPress loads a lot of unnecessary scripts in the header section. Well not really unnecessary – they are useful if you want to use the functionalities provided by these scripts, but in most cases you would not want to use them. These scripts add to page load time which obviously no site owner wants.
So let us see how to get rid of these scripts.
As is the case with most things related to wordpress, there are plugins for this too! But then a plugin adds its own load however small, so we will look for a way to do this without a plugin!
remove really simple discovery service links
rsd_link function adds link to Really Simple Discovery Service endpoint. This link allows 3rd party tools to discover your blog and possibly use pingback to your posts. The link also gives 3rd party tools an endpoint to publish posts to your site – with your explicit permission of course! Remove this link if you are not planning for allowing pingbacks and do not want your 3rd party publishing link to be discovered with this code –
remove wordpress version number
wp_generator function adds a meta tag to the header with wordpress version number. The logic behind removing this version number is that it provides some sort of security by hiding the version – as hackers supposedly have specific hacks for specific wordpress versions! While sophisticated hackers can still find a way to get into your site, still it provides a bit of difficulty for hackers as in security through obscurity! Here is the code –
remove rss feed links
feed_links generates links to rss feeds of post/pages. Unless your wordpress site distributes post/page feeds to 3rd party tools/apps/sites, you may want to remove these links from the header. Use this code –
remove_action('wp_head', 'feed_links', 2);
remove extra feed links
feed_links_extra generates links to rss feeds for categories, comments and tags etc. Some very popular wordpress based news and magazine portals may have use for these links but for majority of other wordpress sites these are pointless. Remove these feed links –
remove_action('wp_head', 'feed_links_extra', 3);
remove link for windows live writer support
wlwmanifest_link adds support for Windows Live Writer. That means – you can use Windows Live Writer to write and publish to your WordPress site. Do you want that? Most likely not! Remove support for Windows Live Writer publishing –
remove post relational links
adjacent_posts_rel_link – displays the relational links for the posts adjacent to the current post. I have not found any practical use of these relational links yet. So unless you have a specific use for these type of links it is probably fine to remove them. Try this –
remove emoji related scripts & Styles
These 2 functions are associated with printing emoji related styles and scripts to both front end and backend headers in wordpress and the code just looks a bit of mess besides adding some overhead to page load time. To remove code bloat added by these functions use the following actions –
remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('wp_print_styles', 'print_emoji_styles');
Remove shortlink tag
wp_shortlink_wp_head– this function adds shortlink for the current page (if any) in the header with rel=shortlink . While shortlinks can be easy to copy paste and use, i fail to see any other use for them. Additionally having 2 URLs for a post/page is not a good idea from a search engine perspective. So can remove this tag with the following action –
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
So putting these code snippets together –
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'); remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
This goes to your functions.php file.
Note that some functions get deprecated when WordPress release new versions. The code snippets above should work on WordPress 4.2 and above.