How to write PHP script to clear the WordPress head redundant code, explain, WordPress redundant _php tutorial

Source: Internet
Author: User
Tags wordpress version

Write a PHP script to clear the WordPress head redundant code to explain the way, WordPress redundancy


WordPress Head code very much, including WordPress version, contextual, the first article, home meta information and other redundant code, these are not meaningful to bloggers, but also on the site's security has a certain impact, and once did not know what the role of these codes, How 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 the large amount of redundant information in WordPress Head

<?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 ', one, 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 theme in header.php this file will use this function, and many plugins in order to add something in the header will also use the Wp_head (), such as the relevant plug-ins SEO. However, at this point in the Wp_head (), there is a lot more code that is not commonly used. You can remove the code through remove_action.

remove_action function

Function Prototypes:

Remove_action ($tag, $function _to_add, $priority, $accepted _args);

The function removes a function attached to the specified action hook. This method can be used to remove the default function attached to a particular action hook and possibly replace it with another function. See Remove_filter (), Add_action () and Add_filter ().
Important: When adding hooks, the $function_to_remove and $priority parameters should be matched so that hooks can be removed. This principle also applies to filters and actions. No warning prompts when removing a failure.
Parameters

    • $tag (String) (required) The action hook to which the function to be removed will be connected. Default value: None
    • $function _to_remove (callback) (required) The name of the function to be deleted default value: None
    • $priority (integer) (optional) function precedence (defined when the function is initially connected) default value: 10
    • $accepted the number of parameters that are accepted by the _args (integer) (required) function. Default value: 1

return value

    • Whether or not the (Boolean) function has been removed.
    • The Ttue function was successfully removed
    • False function not removed

Removing the WordPress version

In the head area, you can see the following code:

 
  

This is the hidden display of WordPress version information, 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 of Offline editor open Interface

 
   
 
  


Where RSD is a generalized interface, Wlwmanifest is for the Microsoft Live Writer editor. If you don't need to edit offline, you can remove it. Even if you need to use an offline editor, these two lines of code are not required most of the time. Live writer knows them by himself. 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 puts contextual, the first article and the homepage link in Meta. I think the 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 ', 10, 0); Removes the prev link remove_action (' wp_head ', ' Start_post_rel_link ', 10, 0); Removes the start link remove_action (' wp_head ', ' adjacent_posts_rel_link_wp_head ', 10, 0); Removes the relational links for the posts adjacent to the current post.

Remove canonical tags

In February 09, Google,yahoo and Microsoft launched a joint effort to reduce the number of repetitive content, which is a good thing for the webmaster, no longer worry because the site has duplicate content and affect the weight of the site page.
There are many reasons for duplicate content, the most common is that multiple URL addresses to the same page, such as: WordPress platform under a log page, including articles and comments 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. When spiders come crawling, they will crawl again, this article if there are 10 comments, then climbed 10 times the same page article, equivalent to do a number of repeated work, seriously affected the efficiency of the crawl, and the cost of bandwidth.
The result of repeating content is necessarily that spiders do not want to crawl, different URLs point to the same page, it will affect the weight of the page. Through the canonical tag, this kind of problem can be effectively avoided.
There are two points to note:

    • Allow pointing to different subdomains, not to other domain names
    • The canonical property can be passed

That is, a page declaration b is authoritative link, B declaration c is authoritative web 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 make the blog support.

 
  

After WordPress 2.9 was released, WordPress has already supported this tag by default, and we do not need to do any action, the theme supports this tag. This is useful for changing the article permalink, which can increase the friendliness of the search engine. But if you think this tag is useless to you, you can remove it:

Remove_action (' Wp_head ', ' rel_canonical ');

Remove Feed

In HTML by

 
  

To specify a 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 FeedBurner-fired feed), you can remove it.

Remove_action (' Wp_head ', ' feed_links ', 2);//articles and comments 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.

Articles you may be interested in:

    • Is WordPress makes PHP more popular than the framework
    • PHP function parsing of custom headers in WordPress theme making
    • Analysis of PHP function usage in debugging thumbnail in WordPress
    • Use of PHP functions to get recent articles in WordPress development
    • Introduction to the use of PHP functions for custom menus in WordPress development
    • The PHP function used in WordPress to get the search form is parsed
    • Detailed PHP functions for creating and adding filters in WordPress
    • PHP functions for creating and getting sidebar in WordPress
    • PHP function parsing for writing custom storage fields in WordPress
    • Examples of PHP code used to update pseudo-static rules in WordPress

http://www.bkjia.com/PHPjc/1105378.html www.bkjia.com true http://www.bkjia.com/PHPjc/1105378.html techarticle write PHP script to clear the WordPress head redundant code of the way to explain, WordPress redundant wordpress head code very much, including WordPress version, contextual, the first article, home me ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.