WordPress Head of the code is very much, including the WordPress version, contextual, the first article, home page meta information and other redundant code, these are meaningless to the blogger, but also to the safety of the site has a certain impact, also did not know what the code is the role of How to come and how to delete.
WordPress Head Cleanup code is as follows
Insert the following code into the header of your functions.php file, except for a large amount of redundant information in the WordPress header
<?php//remove_action (' Wp_head ', ' wp_enqueue_scripts ', 1);
Remove_action (' Wp_head ', ' feed_links ', 2);
Remove_action (' Wp_head ', ' Feed_links_extra ', 3);
Remove_action (' Wp_head ', ' rsd_link ');
Remove_action (' Wp_head ', ' wlwmanifest_link ');
Remove_action (' Wp_head ', ' index_rel_link ');
Remove_action (' Wp_head ', ' Parent_post_rel_link ', 10, 0);
Remove_action (' Wp_head ', ' Start_post_rel_link ', 10, 0);
Remove_action (' Wp_head ', ' adjacent_posts_rel_link_wp_head ', 10, 0);
Remove_action (' Wp_head ', ' locale_stylesheet ');
Remove_action (' Publish_future_post ', ' check_and_publish_future_post ', 10, 1);
Remove_action (' Wp_head ', ' noindex ', 1);
Remove_action (' Wp_head ', ' wp_print_styles ', 8);
Remove_action (' Wp_head ', ' wp_print_head_scripts ', 9);
Remove_action (' Wp_head ', ' wp_generator ');
Remove_action (' Wp_head ', ' rel_canonical ');
Remove_action (' Wp_footer ', ' wp_print_footer_scripts ');
Remove_action (' Wp_head ', ' wp_shortlink_wp_head ', 10, 0); Remove_Action (' Template_redirect ', ' Wp_shortlink_header ', 11, 0);
Add_action (' Widgets_init ', ' My_remove_recent_comments_style ');
function My_remove_recent_comments_style () {global $WP _widget_factory; Remove_action (' Wp_head ', array ($wp _widget_factory->widgets[' wp_widget_recent_comments '), ' Recent_comments_
Style '));
}?>
Each function explains:
Wp_head function
Wp_head () is a very important function of WordPress, basically all the topics in header.php This file will use this function, and many plug-ins in order to add something to the header will also use Wp_head (), such as SEO related plug-ins. However, in this location where Wp_head () is present, a lot of code that is not commonly used is added. This code can be removed by remove_action.
remove_action function
Function Prototypes:
Remove_action ($tag, $function _to_add, $priority, $accepted _args);
This function removes a function that is attached to the specified action hook. This method can be used to remove the default function attached to a specific action hook and may be replaced with another function. See Remove_filter (), Add_action () and Add_filter ().
Important: The $function_to_remove and $priority parameters must be matched when the hook is added so that the hook can be removed. The principle also applies to filters and actions. Do not warn when removal fails.
Parameters
- The action hook that the $tag (string) (required) is connected to the function being deleted. Default value: None
- $function _to_remove (callback) (required) default value for the name of the function to be removed: None
- $priority (integer) (optional) function precedence (defined at the time the function was originally connected) default value: 10
- $accepted the number of parameters that are accepted by the _args (integer) (required) function. Default value: 1
return value
- Whether the (Boolean) function was removed.
- The Ttue function was successfully removed
- The function of false was not removed
Remove the WordPress version
In the head area, you can see the following code:
<meta name= "generator" content= "WordPress 3.1.2"/>
This is the hidden display of WordPress version information, which is added by default. Can be exploited by hackers to attack a specific version of the WordPress vulnerability. Clear code:
Remove_action (' Wp_head ', ' wp_generator ');
Remove Offline Editor Open Interface
WordPress automatically add two lines offline editor open Interface
<link rel= "Edituri" type= "Application/rsd+xml" title= "RSD" href= "HTTP://JB51.NET/XMLRPC.PHP?RSD"/>
< Link rel= "wlwmanifest" type= "Application/wlwmanifest+xml" href= "Http://jb51.net/wp-includes/wlwmanifest.xml"/>
RSD is a broad interface, Wlwmanifest for the Microsoft Live Writer editor. If you do not need to edit offline, you can remove it. Even if you need to use an offline editor, most of the time you don't need these two lines of code. Live writer know them by themselves. Keeping these two lines of code may leave a security risk. Clear code:
Remove_action (' Wp_head ', ' rsd_link ');
Remove_action (' Wp_head ', ' wlwmanifest_link ');
Remove contextual, first article, home page meta information
WordPress put contextual, the first article and the homepage link all in Meta. I think SEO help is not big, reverse makes the head information huge. Remove Code:
Remove_action (' Wp_head ', ' index_rel_link '); Removes the index link
remove_action (' Wp_head ', ' Parent_post_rel_link ', 0);//Removes the prev link
Remo Ve_action (' Wp_head ', ' Start_post_rel_link ', 10, 0); Removes the start link
remove_action (' Wp_head ', ' Adjacent_posts_rel_link_wp_head ', 0);//Removes the Relatio Nal links for the "posts adjacent to the" current post.
Remove canonical tag
In February 09, Google,yahoo and Microsoft's three major search engines jointly launched a solution to reduce duplication of content, which is a good thing for webmaster, no longer worry because the site has duplicate content and affect the weight of the site page.
There are many reasons to duplicate content, the most common is that multiple URL addresses to the same page, such as: WordPress platform under a log page, including the article and comment content. Each comment can have a fixed link address, if there are multiple comments, then each comment link is similar to the above format, but the Commentid number is different, these links are actually pointing to the same article. Spiders crawl, they will crawl in turn again, this article, if there are 10 comments, then climbed 10 times the same page article, equivalent to doing a lot of repetitive work, seriously affecting the crawl efficiency, and the cost of bandwidth.
Repeated content caused by the result is the spider is not willing to crawl, different URLs point to the same page, also affect the weight of the page. By canonical label, this kind of problem can be avoided effectively.
Two points to note:
- Allow pointing to different subdomains, not allowed to point to other domain names
- Canonical properties can be passed
That is, a page to declare B is the authoritative link, B statement c is authoritative page, then C is a and B common preferred authoritative version
If your WP version before 2.9, you need to use the plugin (mentioned above) or manually Hack the theme of the header.php file to enable the blog support.
<link rel= "canonical" Href= "<?php get_permalink ()?>"/>
After the WordPress 2.9 release, WordPress has the default support for this tag, we do not need to do any action, the theme of support for this tag. This is helpful for the change of the article fixed link, can increase the friendliness of the search engine. But if you think the label is useless to you, you can also remove it:
Remove_action (' Wp_head ', ' rel_canonical ');
Remove Feed
In HTML by
<link rel= "Alternate" type= "Application/rss+xml" title= "Feed name" href= "http://jb51.net/feed/"/>
To specify the blog feed. Can be detected by the browser and then subscribed by the reader.
If you don't want to add a feed, or want to use a fired feed (such as a Feedsky or a feedburner-fired feed), you can remove it.
Remove_action (' Wp_head ', ' feed_links ', 2);/article and comment feed
remove_action (' Wp_head ', ' Feed_links_extra ', 3); Categories and other Feeds
If you use a fired feed, you can then add the feed address manually.