說起WordPress主題,我們一般安裝好一款WordPress主題后,查看源代碼,都能看到其頭部太多的信息,而這些信息很多都是無用的,但作為默認的根據wp_head()這個鉤子所加載著,著實有點費事,代碼簡潔控們就不喜歡了,如何精簡WordPress頭部多余信息,去掉部分不必要的js加載呢?我們下面具體說:
修改WordPress系統文件的方法大叔這里就不說了,這樣不好,每次WordPress程序的更新,都得進行一次操作,費事!
下面直接打開您所使用主題的文件里的functions.php吧,對,大家都喜歡將一些拓展函數放這個文件里,方便!
大叔這里還是建議大家將這個文件通過FTP下載下來,先備份,后修改,因為一個不小心,少一個標點都會導致整站打不開!解決方法就是覆蓋備份functions.php文件即可安然無恙!
下面就說重點了:
- remove_action(?‘wp_head’,?‘wp_enqueue_scripts’,?1?);?
- remove_action(?‘wp_head’,?‘feed_links’,?2?);?
- remove_action(?‘wp_head’,?‘feed_links_extra’,?3?);?
- remove_action(?‘wp_head’,?‘rsd_link’?);?
- remove_action(?‘wp_head’,?‘wlwmanifest_link’?);??
- remove_action(?‘wp_head’,?‘index_rel_link’?);
- remove_action(‘wp_head’,?‘parent_post_rel_link’,?10,?0?);
- remove_action(‘wp_head’,?‘start_post_rel_link’,?10,?0?);
- remove_action(?‘wp_head’,?‘adjacent_posts_rel_link_wp_head’,?10,?0?);
- remove_action(?‘wp_head’,?‘locale_stylesheet’?);
- remove_action(‘publish_future_post’,’check_and_publish_future_post’,10,?1?);
- remove_action(?‘wp_head’,?‘noindex’,?1?);
- remove_action(?‘wp_head’,?‘wp_print_styles’,?8?);
- remove_action(?‘wp_head’,?‘wp_print_head_scripts’,?9?);
- remove_action(?‘wp_head’,?‘wp_generator’?);?
- remove_action(?‘wp_head’,?‘rel_canonical’?);
- remove_action(?‘wp_footer’,?‘wp_print_footer_scripts’?);
- remove_action(?‘wp_head’,?‘wp_shortlink_wp_head’,?10,?0?);
- remove_action(?‘template_redirect’,?‘wp_shortlink_header’,?11,?0?);
- add_action(‘widgets_init’,?‘my_remove_recent_comments_style’);
- function?my_remove_recent_comments_style()?{
- global?$wp_widget_factory;
- remove_action(‘wp_head’,?array($wp_widget_factory->widgets[‘WP_Widget_Recent_Comments’]?,’recent_comments_style’));
- }
- if?(?!is_admin()?)?{?
- function?my_init_method()?{
- wp_deregister_script(?‘jquery’?);?
- }
- add_action(‘init’,?‘my_init_method’);
- }
- wp_deregister_script(?‘l10n’?);
將以上代碼貼進functions.php內,保存、上傳。。刷新網頁,查看源文件,看頭部是否干凈了許多?原本加載了很多的js是否都不見了??呵呵,不用謝大叔,大叔叫雷鋒!