2010-06-20 36 views
4

不工作我已經用在WordPress中remove_action函數之前由wp_head注入刪除垃圾,但似乎與3.0版本沒有被類似下面去掉了一些標籤:wp_head remove_action在WP3.0

remove_action('wp_head', 'parent_post_rel_link', 10, 0); 

這應該刪除prev鏈接標記,但它不是。有人知道原因嗎?

+3

檢查'WP-包括/缺省過濾器'181'行的'.php'以查看附加到'wp_head'的所有默認操作 - 它可能是'start_post_rel_link'? – TheDeadMedic 2010-06-20 21:49:32

+0

感謝您的指針!我找到了解決辦法,見下文。 – UXTE 2010-06-21 00:03:34

回答

10

感謝TheDeadMedic,我在「wp-includes/default-filters.php」中找到了解決方案。下面去除wp_head next和prev鏈接:

remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); 

這是從<head>刪除所有 「不必要的」 meta標籤的完整劇本:

//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')); 
} 
+1

你有沒有參考wp_head中的所有東西? 「不必要」有點不祥。另外,這適用於什麼版本的WordPress? – LeRoy 2011-04-05 20:10:47