本帖最後由 termjoy 於 2012-5-31 16:16 編輯 9 s2 A9 [( ?7 h
; g- n( p1 y% ^6 K: q3 T& tWordPress主題文件裡的header.php中引用的 輸出的很多內容沒有任何意義,服務器響應的次數,此部分內容實際上並沒有多大的意義,這裡介紹一下怎麼優化wp_head()內容的內容。+ D3 m" ]$ q" X" p6 N
0 S& q' @6 H( p) k; a2 N
默認情況下,WordPress輸出內容:- <link rel=」alternate」 type=」application/rss+xml」 title=」這篇文章的 評論 Feed」 href=」http://www.domain.com/10.html/feed」 />
& z. S, V$ P# J1 C - <script type=』text/javascript』 src=』http://www.domain.com/wp-includes/js/l10n.js?ver=20101110′></script>
7 H8 H, O& B4 k; D' R. _ - <script type=』text/javascript』 src=』http://www.domain.com/wp-includes/js/comment-reply.js?ver=20090102′></script>2 { \3 x, [ t* a3 @
- <link rel=」EditURI」 type=」application/rsd+xml」 title=」RSD」 href=」http://www.domain.com/xmlrpc.php?rsd」 />9 V; F' H) S: d2 t f
- <link rel=」wlwmanifest」 type=」application/wlwmanifest+xml」 href=」http://www.domain.com/wp-includes/wlwmanifest.xml」 />* o- Y. ~* g+ E q6 q$ [# z
- <link rel=』index』 title=』我得Blog』 href=』http://www.domain.com』 />
" k6 \1 H' V3 ]$ N+ i& U7 y - <link rel=』start』 title=』第一篇文正』 href=』http://www.domain.com/11.html』 />+ [0 R% L; e2 @7 q6 _
- <link rel=』prev』 title=』前面一片文章』 href=』http://www.domain.com/12.html』 />1 b" [, q8 i* V+ G, W) G
- <link rel=』next』 title=』下面一篇文章』 href=』http://www.domain.com/guid.html』 />
8 ]0 a; {/ i8 j) V! w3 k3 F+ Y5 @ - <meta name=」generator」 content=」WordPress 3.2.1〞 />
b W% q/ \7 T' q7 f. P, Y6 P - <link rel=』shortlink』 href=』http://www.domain.com/?p=10′ />) O' d d6 b4 Z6 o) w+ R
複製代碼 從上面的內容看很多東西可以直接刪掉,修改當前主題代碼
% P: d" j: e/ x1 \9 F! N+ C3 K: T$ ]% c+ L. K
打開主題文件下的 functions.php 文件。添加如下代碼(具體要刪除哪些自己決定):- // Actions
e% _4 f5 j- r7 L( R. v/ T3 r - remove_action( 『wp_head』, 『wp_enqueue_scripts』, 1 );
- ?- H# L$ g8 g G& a: G) T - remove_action( 『wp_head』, 『feed_links』, 2 );
! [4 x) H! p7 O# u/ h - remove_action( 『wp_head』, 『feed_links_extra』, 3 );
8 V% k$ R |9 r1 v; q& G - remove_action( 『wp_head』, 『rsd_link』 );
5 {; `& ^, W7 t; T; I+ ~% ? - remove_action( 『wp_head』, 『wlwmanifest_link』 );
) t/ N6 l$ o O1 V - remove_action( 『wp_head』, 『index_rel_link』 );& H+ q# f# J% @1 {
- remove_action( 『wp_head』, 『parent_post_rel_link』, 10, 0 );
y, w; \. u# h4 K) ` - remove_action( 『wp_head』, 『start_post_rel_link』, 10, 0 );
9 w- k* H$ J9 e& d; G1 E' J - remove_action( 『wp_head』, 『adjacent_posts_rel_link_wp_head』, 10, 0 );' M+ W3 q5 l" b, E5 M* s
- remove_action( 『wp_head』, 『locale_stylesheet』 );6 w/ o/ `7 k: y- w$ \: J
- remove_action( 『wp_head』, 『noindex』, 1 );
- O* G% U/ Z& G0 z6 N1 x; ]* J - remove_action( 『wp_head』, 『wp_print_styles』, 8 );
1 X/ h4 |6 O3 ~ - remove_action( 『wp_head』, 『wp_print_head_scripts』, 9 );
# G% e0 D. D8 B - remove_action( 『wp_head』, 『wp_generator』 );
& E; S) K6 U0 \+ u T5 ? - remove_action( 『wp_head』, 『rel_canonical』 );
; O* T" Y, L0 v+ `0 c3 ? - remove_action( 『wp_head』, 『wp_shortlink_wp_head』, 10, 0 );* P: J* |. S( }& B' f' q* u
複製代碼 注意:上面代碼中的引號需要替換一下。。。不要直接使用 |
|