本帖最後由 termjoy 於 2012-5-31 16:16 編輯 8 P* J _$ P# M
4 F/ i) O1 o0 N* u- [& A1 h# o( jWordPress主題文件裡的header.php中引用的 輸出的很多內容沒有任何意義,服務器響應的次數,此部分內容實際上並沒有多大的意義,這裡介紹一下怎麼優化wp_head()內容的內容。
( V1 I! B' C! \& }, c! i
, G* d" [8 j$ M' U0 R' x6 x, P9 E默認情況下,WordPress輸出內容:- <link rel=」alternate」 type=」application/rss+xml」 title=」這篇文章的 評論 Feed」 href=」http://www.domain.com/10.html/feed」 />8 V4 a% A0 h) y8 z! c( O# a w
- <script type=』text/javascript』 src=』http://www.domain.com/wp-includes/js/l10n.js?ver=20101110′></script>0 h& A' R2 I3 G$ |7 P2 c: t/ T
- <script type=』text/javascript』 src=』http://www.domain.com/wp-includes/js/comment-reply.js?ver=20090102′></script>
- t) [. t6 v$ [& g( Z - <link rel=」EditURI」 type=」application/rsd+xml」 title=」RSD」 href=」http://www.domain.com/xmlrpc.php?rsd」 />2 S* ?+ [- k; }5 H% X4 T
- <link rel=」wlwmanifest」 type=」application/wlwmanifest+xml」 href=」http://www.domain.com/wp-includes/wlwmanifest.xml」 />
% d. z( k. D0 H/ n @3 C) f - <link rel=』index』 title=』我得Blog』 href=』http://www.domain.com』 />" o5 M9 f2 c5 G$ u1 E( Y3 N
- <link rel=』start』 title=』第一篇文正』 href=』http://www.domain.com/11.html』 />, n, q' v* S; k
- <link rel=』prev』 title=』前面一片文章』 href=』http://www.domain.com/12.html』 />7 ~; S* _0 Q2 B2 _
- <link rel=』next』 title=』下面一篇文章』 href=』http://www.domain.com/guid.html』 />" F5 b1 n& I! s$ {
- <meta name=」generator」 content=」WordPress 3.2.1〞 />
+ _7 Q4 L8 Y" U+ Y4 a7 @: } - <link rel=』shortlink』 href=』http://www.domain.com/?p=10′ />
8 n, r. M$ z6 e$ ^/ n: \" t) x
複製代碼 從上面的內容看很多東西可以直接刪掉,修改當前主題代碼% E! @3 f W5 I7 G: Y9 f
, A9 V2 Y+ {4 L9 O% e# P
打開主題文件下的 functions.php 文件。添加如下代碼(具體要刪除哪些自己決定):- // Actions
5 e# T; }1 F0 \# u, o3 J3 ` - remove_action( 『wp_head』, 『wp_enqueue_scripts』, 1 );
) y6 p2 M5 S$ U: k. G4 [- l - remove_action( 『wp_head』, 『feed_links』, 2 );" |6 j0 H& l; T& g# H8 Z! a
- remove_action( 『wp_head』, 『feed_links_extra』, 3 );1 w% _, f7 m! u2 `
- remove_action( 『wp_head』, 『rsd_link』 );
" {) Q: R: X" H1 A; O9 R+ G. G - remove_action( 『wp_head』, 『wlwmanifest_link』 );
# R w, D9 C* r, @1 k2 j" E7 _ - remove_action( 『wp_head』, 『index_rel_link』 );
3 ~- ~) j7 ^/ f/ i - remove_action( 『wp_head』, 『parent_post_rel_link』, 10, 0 );0 n2 B8 n/ I% b7 a
- remove_action( 『wp_head』, 『start_post_rel_link』, 10, 0 );9 }0 L7 w0 n: `8 Y
- remove_action( 『wp_head』, 『adjacent_posts_rel_link_wp_head』, 10, 0 );
9 h4 O. u0 v6 J2 n+ W0 Z6 S' ]# q - remove_action( 『wp_head』, 『locale_stylesheet』 );& I' j$ l- |, e, g Q3 S
- remove_action( 『wp_head』, 『noindex』, 1 );$ f. V( l% p( r% ^1 P
- remove_action( 『wp_head』, 『wp_print_styles』, 8 );
; _% P5 M; C9 z; a, s - remove_action( 『wp_head』, 『wp_print_head_scripts』, 9 );4 t- A% Z2 H$ p2 R
- remove_action( 『wp_head』, 『wp_generator』 );
" M" m/ y+ X% k [6 `2 f, G( m - remove_action( 『wp_head』, 『rel_canonical』 );
6 k M" X% {; h - remove_action( 『wp_head』, 『wp_shortlink_wp_head』, 10, 0 );
# y: e( H, {" B/ ]. |9 W
複製代碼 注意:上面代碼中的引號需要替換一下。。。不要直接使用 |
|