There are Hundreds of Junks on WordPress Header, From Meta Name Generator To Post RSS. Here is How To Remove the Junks From WordPress Header. This guide is nothing new, frankly, there are lot of good guides on the same topic. Yet, you might get some links to the older guides which are helpful and 100% unique. Also, a practical fact – own blog work as own guide. It is not possible to remember everything like this stuffs.
Why We Remove Junks From WordPress Header
First reason is security – if your version of WordPress is publicly visible, except the hackers, script kiddies and NSA Agents, none basically need them. There can version specific backdoor or security flaw. Second reason is to speed up – not all the posts can be cached within 5 minutes – if you have 5K posts like us; with even a 4GB server plus different MySQL server, it takes a good time to write the Cache. HTML pages are not always served by W3TC by plugins, specially after publication of a post. Third reason is SEO – bots dislike same kind of useless data on every WordPress installation. Also, Post Feed can give 404. These are some of the reasons to remove these. Really Simple Discovery (RSD) sounds like a rocket science, normally this is not needed. You must know that :
Keeping the Main RSS Feed, that is usually of Feedburner; is essential for many web services. For that reason, you can simply add a static thing like this via either your Theme’s settings page or Header and Footer like Plugin :
---
1 | <link rel=“alternate” type=“application/rss+xml” title=“The Customize Windows » Feed” href=“http://feeds.feedburner.com/TheCustomizeWindows”/> |
http://feeds.feedburner.com/TheCustomizeWindows is our Feed. You must change it to yours one. Our WordPress default Feed is here – https://thecustomizewindows.com/feed/. As you know, Feedburner does not support HTTPS (at the time of writing). This is HSTS website. We do a different kind of cheating to reflect the changes on Feedburner. We use Akamai now! A bash script does the work.
Remove Junks From WordPress Header
Here are the things :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // Removes the RSD link remove_action(‘wp_head’, ‘rsd_link’); // Removes the WordPress version remove_action(‘wp_head’, ‘wp_generator’); // Removes the main RSS feed which we were talking about remove_action(‘wp_head’, ‘feed_links’, 2); // Removes all the others extra RSS feed links remove_action(‘wp_head’, ‘feed_links_extra’, 3); // Remove link to index page remove_action(‘wp_head’, ‘index_rel_link’); // Removes windows live writer support remove_action(‘wp_head’, ‘wlwmanifest_link’); // Removes the random post link, may be injected by plugins remove_action(‘wp_head’, ‘start_post_rel_link’, 10, 0); remove_action(‘wp_head’, ‘parent_post_rel_link’, 10, 0); 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 ); remove_action(‘wp_head’, ‘rel_canonical’, 10, 0 ); |
The commented out lines are for your understanding. Here is the clean version :
1 2 3 4 5 6 7 8 9 10 11 12 | 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’, ‘index_rel_link’); remove_action(‘wp_head’, ‘wlwmanifest_link’); remove_action(‘wp_head’, ‘start_post_rel_link’, 10, 0); remove_action(‘wp_head’, ‘parent_post_rel_link’, 10, 0); 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 ); remove_action(‘wp_head’, ‘rel_canonical’, 10, 0 ); |
Where you’ll add these? You’ll add these on your WordPress Theme (or Child Theme’s) functions.php
file via (S)FTP or SSH. Yes, adding on wp-config.php
might work, but that is not what normally people do. You can also Remove jquery.js and jquery-migrate.js in WordPress. It needs a bit care. You can remove the CSS and JS version too :
1 2 3 4 5 6 7 8 | // removes the fucking ?ver= stuffs, needed for HSTS function remove_cssjs_ver( $src ) { if( strpos( $src, ‘?ver=’ ) ) $src = remove_query_arg( ‘ver’, $src ); return $src; } add_filter( ‘style_loader_src’, ‘remove_cssjs_ver’, 1000 ); add_filter( ‘script_loader_src’, ‘remove_cssjs_ver’, 1000 ); |
If you do not use a good Syntax highlighter, back ticks will not make an inline code – if( strpos( $src,
, this is a thing, which you’ll add not remove – here is how to convert back ticks to code.
Advanced (Optional) :
Whatever you will add, you can make it a simple plugin (remove the commented out lines, add your own stuffs) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php /** * Plugin Name: Head and Shoulder * Plugin URI: please type your own website url * Description: Head and Shoulder cleans dandruff of WordPress head * Version: 1.0.0 * Author: Your Name * Author UI: please type your own website url * License: GNU GPL 3.0 */ remove_action(‘wp_head’, ‘rsd_link’); // add all the stuffs and save as something named like // head–and–shoulder.php // zip it. upload via WP Plugin adding page // do not add php closure, your wordpress will die |
Easy thing. So many people wrote the same thing; but none of them added a real screenshot of SSH screen, where actually we worked to add them. If it was faulty, you could not read this webpage!
P.S. : Removing the RSS stuffs can decrease the page loading speed quite paranormally.
Tagged With index_rel_link wp_head 2015 , wordpress remove_action rsd_link