Write a PHP script to clear the WordPress header redundancy code. Compile a PHP script to clear the WordPress header redundancy code. There are many wordpress redundant header code, including the wordpress version, post and post, first article, home page me PHP script to clear WordPress header redundant code explanation, wordpress redundancy
There are a lot of code in the wordpress header, including the WordPress version, the prefix, the first article, the meta information on the homepage, and other redundant code, which is meaningless to the blogger, it also has a certain impact on the security of the website, and once did not know what the code is for, how to come, and how to delete it.
The wordpress header cleanup code is as follows:
Insert the following code into the file header of your functions. php file. in addition to 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')); } ?>
Function description:
Wp_head function
Wp_head () is a very important function of wordpress. basically, all themes are in the header. this function is used in the php file, and many plug-ins also use wp_head () to add something to the header, such as SEO-related plug-ins. However, the position where wp_head () appears will add a lot of less commonly used code. You can use remove_action to remove the code.
Remove_action function
Function prototype:
remove_action( $tag, $function_to_add, $priority, $accepted_args );
This function removes a function attached to the specified action hook. This method can be used to remove the default functions attached to the hook of a specific action, and may be replaced by other functions. See remove_filter (), add_action () and add_filter ().
Important: The $ function_to_remove and $ priority parameters of the hook must match to remove the hook. This principle also applies to filters and actions. No warning is prompted when the removal fails.
Parameters
- $ Tag (string) (required) the action hook to which the function to be deleted is connected. Default value: None
- $ Function_to_remove (callback) (required) name of the function to be deleted default value: None
- $ Priority (integer) (optional) function priority (defined when the function is initially connected) default value: 10
- $ Accepted_args (integer) (required) number of parameters accepted by the function. Default value: 1
Return value
- (Boolean) whether the function is removed.
- The Ttue function is successfully removed.
- The False function is not removed.
Remove WordPress version
In the head area, you can see the following code:
This is the hidden display of WordPress version information, which is added by default. Attackers can exploit this vulnerability to attack a specific version of WordPress. Clear code:
remove_action( 'wp_head', 'wp_generator' );
Remove offline editor APIs
WordPress automatically adds two open interfaces for offline editors
In this example, RSD is a generalized interface, and wlwmanifest is for the Microsoft Live Writer editor. If you do not need to edit it offline, you can remove it. Even if you need an offline editor, most of the time you do not need the two lines of code. Live Writer knows them. Keeping these two lines of code may leave security risks. Clear code:
remove_action( 'wp_head', 'rsd_link' ); remove_action( 'wp_head', 'wlwmanifest_link' );
Remove text, first article, and homepage meta information
WordPress stores all the text, first article, and homepage links in meta. I don't think SEO is helpful, but it makes the header 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 flag
In September February, Google, Yahoo, and Microsoft jointly launched a method designed to reduce repeated content troubles, which is a good thing for webmasters, there is no need to worry that duplicate content on the website will affect the weight of the website page.
There are many reasons for duplicate content. The most common reason is that multiple URLs point to the same page, for example, a log page under the wordpress platform, including the article and comments. Each comment can have a fixed link address. if there are multiple comments, the links of each comment are similar to the above format, but the commentID number is different, these links actually point to the same chapter. When a spider crawls, the spider crawls the pages one by one. if there are 10 comments in this article, the spider crawls the same page Article 10 times, which is equivalent to repeating the work multiple times, it seriously affects the capture efficiency and bandwidth consumption.
The result of repeated content is that the spider does not want to crawl. different URLs direct to the same page, which also affects the weight of the page. Canonical labels can effectively avoid such problems.
Pay attention to the following two points:
- It can direct to different subdomain names, not to other domain names
- Canonical attributes can be passed
That is, if page A declares that page B is an authoritative link and page B declares that page C is an authoritative webpage, C is the preferred authoritative version for both A and B.
If your WP version is earlier than 2.9, you need to use the plug-in (as mentioned above) or the header. php file of the manual Hack topic to support your blog.
After WordPress 2.9 is released, WordPress supports this tag by default. you do not need to perform any actions, and the topic supports this tag. This is helpful for changing the fixed link of the article and increases the friendliness of the search engine. But if you think this label is useless to you, you can also remove it:
remove_action( 'wp_head', 'rel_canonical' );
Remove feed
In HTML
To specify the blog feed. It can be detected by the browser and subscribed by the reader.
If you do not want to add a feed or want to use a burned feed (such as a feed fired by FeedSky or Feedburner), you can remove it.
Remove_action ('WP _ head', 'Feed _ links ', 2); // articles and comments feed remove_action ('WP _ head', 'Feed _ links_extra', 3 ); // category and other feeds
If you use a burned feed, you can also manually add the feed address.
Articles you may be interested in:
- WordPress makes PHP more popular than the framework
- Analysis of PHP functions related to custom headers in WordPress topic creation
- Use of PHP functions for debugging thumbnails in WordPress
- Analysis of PHP functions used for obtaining recent articles in WordPress development
- Introduction to using custom menu related PHP functions in WordPress development
- Use of PHP functions used to retrieve search forms in WordPress
- Describes the PHP functions used to create and add filters in WordPress.
- PHP functions used to create and retrieve sidebar in WordPress
- PHP function parsing for writing custom storage fields in WordPress
- PHP code example for updating pseudo-static rules in WordPress
The wordpress header contains a lot of code, including the WordPress version, prefix, first article, and homepage me...