wordpress wp_head() 作用详解
wp_head()是wordpress的一个特别重要的函数,基本上所有的主题在header.php这个文件里都会使用到这个函数。
而且很多插件为了在header上加点东西也会会到wp_head(),比如SEO插件。
但是,在wp_head()出现的这个位置,会增加很多并不常用的代码,比如:
<link rel=”EditURI” type=”application/rsd+xml” title=”RSD” href=”https://www.xuewangzhan.net/xmlrpc.php?rsd” />
<link rel=”wlwmanifest” type=”application/wlwmanifest+xml” href=”https://www.xuewangzhan.net/wp-includes/wlwmanifest.xml” />
<link rel=’index’ title=’WordPress教程网’ href=’https://www.xuewangzhan.net’ />
<meta name=”generator” content=”WordPress 3.0.4″ />
<link rel=”wlwmanifest” type=”application/wlwmanifest+xml” href=”https://www.xuewangzhan.net/wp-includes/wlwmanifest.xml” />
<link rel=’index’ title=’WordPress教程网’ href=’https://www.xuewangzhan.net’ />
<meta name=”generator” content=”WordPress 3.0.4″ />
这些代码并不是必须的。但是删除wp_head()并不是一个很好的选择,因为这样会影响到一些插件的使用。
那我们该怎么删除这些代码呢?
方法也很简单:
到主题的functions.php这个文件里。如果没有,则自己创建,一般正常的wordpress主题都会有。在最后加上这一段:
remove_action( ‘wp_head’, ‘feed_links_extra’, 3 ); // Display the links to the extra feeds such as category feeds
remove_action( ‘wp_head’, ‘feed_links’, 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action( ‘wp_head’, ‘rsd_link’ ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( ‘wp_head’, ‘wlwmanifest_link’ ); // Display the link to the Windows Live Writer manifest file.
remove_action( ‘wp_head’, ‘index_rel_link’ ); // index link
remove_action( ‘wp_head’, ‘parent_post_rel_link’, 10, 0 ); // prev link
remove_action( ‘wp_head’, ‘start_post_rel_link’, 10, 0 ); // start link
remove_action( ‘wp_head’, ‘adjacent_posts_rel_link’, 10, 0 ); // Display relational links for the posts adjacent to the current post.
remove_action( ‘wp_head’, ‘wp_generator’ ); // Display the XHTML generator that is generated on the wp_head hook, WP version
remove_action( ‘wp_head’, ‘feed_links’, 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action( ‘wp_head’, ‘rsd_link’ ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( ‘wp_head’, ‘wlwmanifest_link’ ); // Display the link to the Windows Live Writer manifest file.
remove_action( ‘wp_head’, ‘index_rel_link’ ); // index link
remove_action( ‘wp_head’, ‘parent_post_rel_link’, 10, 0 ); // prev link
remove_action( ‘wp_head’, ‘start_post_rel_link’, 10, 0 ); // start link
remove_action( ‘wp_head’, ‘adjacent_posts_rel_link’, 10, 0 ); // Display relational links for the posts adjacent to the current post.
remove_action( ‘wp_head’, ‘wp_generator’ ); // Display the XHTML generator that is generated on the wp_head hook, WP version