本帖最後由 termjoy 於 2012-5-31 16:16 編輯 / R& [1 A1 K G O* F9 m
: c [( _* u- b* [) Y3 iWordPress主題文件裡的header.php中引用的 輸出的很多內容沒有任何意義,服務器響應的次數,此部分內容實際上並沒有多大的意義,這裡介紹一下怎麼優化wp_head()內容的內容。. U( O0 _ m9 h, @# G9 g
' s2 S7 L1 Z! h- `3 F默認情況下,WordPress輸出內容:- <link rel=」alternate」 type=」application/rss+xml」 title=」這篇文章的 評論 Feed」 href=」http://www.domain.com/10.html/feed」 />3 u" g* s5 a: q5 L( `5 d; p
- <script type=』text/javascript』 src=』http://www.domain.com/wp-includes/js/l10n.js?ver=20101110′></script>
! ~' q9 u) l5 }1 y/ X0 k% ] - <script type=』text/javascript』 src=』http://www.domain.com/wp-includes/js/comment-reply.js?ver=20090102′></script>
2 d: W; d M6 Q% a+ V" { - <link rel=」EditURI」 type=」application/rsd+xml」 title=」RSD」 href=」http://www.domain.com/xmlrpc.php?rsd」 />
0 L6 C0 {9 l! J5 [6 c - <link rel=」wlwmanifest」 type=」application/wlwmanifest+xml」 href=」http://www.domain.com/wp-includes/wlwmanifest.xml」 />7 c9 X) }1 o0 |/ ]2 H! h
- <link rel=』index』 title=』我得Blog』 href=』http://www.domain.com』 />- o4 R0 f6 N5 s! y# S
- <link rel=』start』 title=』第一篇文正』 href=』http://www.domain.com/11.html』 />
0 _0 n4 R. ~3 d8 ^+ Q( V4 ` - <link rel=』prev』 title=』前面一片文章』 href=』http://www.domain.com/12.html』 />
: N9 j& @ L7 h - <link rel=』next』 title=』下面一篇文章』 href=』http://www.domain.com/guid.html』 />9 i# [' r% a/ c
- <meta name=」generator」 content=」WordPress 3.2.1〞 />: O/ p8 C$ ~0 D- A
- <link rel=』shortlink』 href=』http://www.domain.com/?p=10′ />
- F1 E) R9 b1 f" f. G+ e
複製代碼 從上面的內容看很多東西可以直接刪掉,修改當前主題代碼4 e9 ?, n& z3 ?4 l3 _
/ Q8 L/ u% W m& P
打開主題文件下的 functions.php 文件。添加如下代碼(具體要刪除哪些自己決定):- // Actions
# c& J* ]) G2 J4 Y: G% \" X! p - remove_action( 『wp_head』, 『wp_enqueue_scripts』, 1 );) t& P2 E) Q3 W% o( F- P; m" u
- remove_action( 『wp_head』, 『feed_links』, 2 );
8 |0 I: ^; _+ s/ H' i" p' R! n - remove_action( 『wp_head』, 『feed_links_extra』, 3 );
# j. G( |' S; E, `" [2 S2 I - remove_action( 『wp_head』, 『rsd_link』 );1 J" h, v/ S8 p/ l5 E( ^
- remove_action( 『wp_head』, 『wlwmanifest_link』 );" B& q8 ~1 c# M3 u& W- N$ U! L# s
- remove_action( 『wp_head』, 『index_rel_link』 );1 j; y7 [$ S( Q4 Z
- remove_action( 『wp_head』, 『parent_post_rel_link』, 10, 0 );
3 G' Z- c4 H$ c+ Z4 E - remove_action( 『wp_head』, 『start_post_rel_link』, 10, 0 );
4 b2 F" B$ A0 V M* _! e$ s4 E# t - remove_action( 『wp_head』, 『adjacent_posts_rel_link_wp_head』, 10, 0 );
u7 e9 y) Q. x1 u+ t3 V/ B% D - remove_action( 『wp_head』, 『locale_stylesheet』 );( X& i8 G* P. M5 |" j/ ^ h
- remove_action( 『wp_head』, 『noindex』, 1 );4 \$ t& h7 \7 H% `0 D/ T
- remove_action( 『wp_head』, 『wp_print_styles』, 8 );# {+ Q9 S/ U' F; Y( t# A. Y
- remove_action( 『wp_head』, 『wp_print_head_scripts』, 9 );' Y0 P! K" V d/ d
- remove_action( 『wp_head』, 『wp_generator』 );
& \4 P/ N. A: i7 N0 t/ w6 q5 W - remove_action( 『wp_head』, 『rel_canonical』 );
) x% e5 Y4 I: O1 j( @$ n0 g - remove_action( 『wp_head』, 『wp_shortlink_wp_head』, 10, 0 );- K" o0 j& b* Z' K9 p/ r
複製代碼 注意:上面代碼中的引號需要替換一下。。。不要直接使用 |
|