本帖最後由 termjoy 於 2012-5-31 16:16 編輯 6 O& [& q: d% k; X0 t
+ i5 b! N( ~2 Q
WordPress主題文件裡的header.php中引用的 輸出的很多內容沒有任何意義,服務器響應的次數,此部分內容實際上並沒有多大的意義,這裡介紹一下怎麼優化wp_head()內容的內容。) C# m0 D6 u; y) U$ U5 H
. k8 \* V5 K& J7 i* u
默認情況下,WordPress輸出內容:- <link rel=」alternate」 type=」application/rss+xml」 title=」這篇文章的 評論 Feed」 href=」http://www.domain.com/10.html/feed」 />" v2 o" A1 v/ g) f* ]5 Y0 B5 `- K
- <script type=』text/javascript』 src=』http://www.domain.com/wp-includes/js/l10n.js?ver=20101110′></script>2 E7 E% f% k, v2 z1 l8 A( l
- <script type=』text/javascript』 src=』http://www.domain.com/wp-includes/js/comment-reply.js?ver=20090102′></script>
1 i' W# f* t/ L! y, Z* n* r - <link rel=」EditURI」 type=」application/rsd+xml」 title=」RSD」 href=」http://www.domain.com/xmlrpc.php?rsd」 />
* ?0 ^( F1 w+ e* P3 m2 H - <link rel=」wlwmanifest」 type=」application/wlwmanifest+xml」 href=」http://www.domain.com/wp-includes/wlwmanifest.xml」 /> \. R( }( v! ^$ i& g
- <link rel=』index』 title=』我得Blog』 href=』http://www.domain.com』 />9 q# y( ~7 b3 u/ P
- <link rel=』start』 title=』第一篇文正』 href=』http://www.domain.com/11.html』 />6 l/ n# Y z( q2 ^* L" G
- <link rel=』prev』 title=』前面一片文章』 href=』http://www.domain.com/12.html』 />
C4 H# l( w4 D2 p - <link rel=』next』 title=』下面一篇文章』 href=』http://www.domain.com/guid.html』 />) Z/ {0 I7 P4 X/ @$ _0 E- J" ^$ C
- <meta name=」generator」 content=」WordPress 3.2.1〞 />. b5 C7 a( _; J- E' N4 [, l3 r
- <link rel=』shortlink』 href=』http://www.domain.com/?p=10′ />$ P6 q! H( H" U* R' _9 v) j
複製代碼 從上面的內容看很多東西可以直接刪掉,修改當前主題代碼8 t5 @) Q3 R- x* s+ c- k
$ p; K7 _5 W8 y! c6 p9 n, L打開主題文件下的 functions.php 文件。添加如下代碼(具體要刪除哪些自己決定):- // Actions; q3 G* w2 F# ]/ q
- remove_action( 『wp_head』, 『wp_enqueue_scripts』, 1 );
0 N# C. U" U8 Q ]9 Z4 x - remove_action( 『wp_head』, 『feed_links』, 2 );6 P3 i6 {0 h, D S4 m
- remove_action( 『wp_head』, 『feed_links_extra』, 3 );
! M, \6 ^; u6 w6 [2 ]" [ - remove_action( 『wp_head』, 『rsd_link』 );( |8 N3 W) D; j+ N
- remove_action( 『wp_head』, 『wlwmanifest_link』 );
* l+ f! m9 L5 k- R - remove_action( 『wp_head』, 『index_rel_link』 );2 Y: @2 A4 P& X( b6 h
- remove_action( 『wp_head』, 『parent_post_rel_link』, 10, 0 );) N' p, N5 u8 I0 W& W2 e1 I& I" K
- remove_action( 『wp_head』, 『start_post_rel_link』, 10, 0 );/ m9 D' D5 y1 Z) A0 f
- remove_action( 『wp_head』, 『adjacent_posts_rel_link_wp_head』, 10, 0 );5 z S6 e' x( c7 ?
- remove_action( 『wp_head』, 『locale_stylesheet』 );& e0 l( b& x/ [5 g' ^
- remove_action( 『wp_head』, 『noindex』, 1 );
( X2 m( t; K4 t6 v - remove_action( 『wp_head』, 『wp_print_styles』, 8 );
2 j4 {' [# a& n( p3 ~$ V5 E - remove_action( 『wp_head』, 『wp_print_head_scripts』, 9 );! C4 I1 A( t- h* l* w
- remove_action( 『wp_head』, 『wp_generator』 );
) p9 }8 I- G" f$ d* @ B - remove_action( 『wp_head』, 『rel_canonical』 );; b2 N! m& C- l, [: n
- remove_action( 『wp_head』, 『wp_shortlink_wp_head』, 10, 0 );' _4 }9 @5 h& ?# G" x
複製代碼 注意:上面代碼中的引號需要替換一下。。。不要直接使用 |
|