去除wordpress頭部不必要的元素標
完整的wordpress頭部清理代碼
<?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’));
}
>把這段代碼插入到主題的functions.php文件下,就可以清除WordPress頭部很多的冗余信息。下面說說這些代碼的具體意義是什麽,以免刪除某些妳想保留的功能。
wp_head()函數
wp_head()是wordpress的壹個非常重要的函數,基本上所有的主題在header.php這個文件裏都會使用到這個函數,而且很多插
件為了在header上加點東西也會用到wp_head(),比如SEO的相關插件。不過在wp_head()出現的這個位置,會增加很多並不常用的代
碼,如何刪除呢?可以通過remove_action移除這些代碼。
remove_action函數
函數原型:remove_action( $tag, $function_to_add, $priority, $accepted_args );
該函數移除壹個附屬於指定動作hook的函數。該方法可用來移除附屬於特定動作hook的默認函數,並可能用其它函數取而代之。
重要:添加hook時的$function_to_remove 和$priority參數要能夠相匹配,這樣才可以移除hook。該原則也適用於過濾器和動作。移除失敗時不進行警告提示。 文章來自
參數 文章來自
1.$tag(字符串)(必需)將要被刪除的函數所連接到的動作hook。默認值:None
2.$function_to_remove(回調)(必需) 將要被刪除函數的名稱默認值:None
3.$priority(整數)(可選)函數優先級(在函數最初連接時定義)默認值:10
4.$accepted_args(整數)(必需)函數所接受參數的數量。默認值:1
返回值
(布爾值)函數是否被移除。
1.Ttue 函數被成功移除
2.False函數未被移除