去掉那些header里不重要的元素,写在 WP_HEAD() 的前面:
wp_deregister_script('l10n');//卸载l10n.js
remove_action('wp_head','rel_canonical');
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'index_rel_link' ); // index link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Display relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version
remove_action('wp_head', 'rel_canonical');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10,0);
remove_action('wp_head', 'locale_stylesheet');
remove_action('wp_head', 'noindex');
remove_action('wp_head', 'wp_print_styles');
remove_action('wp_head', 'wp_print_head_scripts');
去除 WPML 的 generator meta
remove_action( 'wp_head', array($sitepress, 'meta_generator_tag' ) );
有时候 plugin 注册进来的 action, 可以去插件里面找到 action 的名字,一般会像这样
// Load our js and css files add_action( 'wp_print_styles', array($this, 'enqueue_styles') ); add_action( 'wp_print_scripts', array($this, 'enqueue_scripts') );
有时和你不能有选择的去除这些,或许就直接全部去除吧,然后再根据自己的意愿手动加载管理:
remove_all_actions('wp_print_styles'); //插件的CSS
remove_all_actions('wp_print_scripts'); // 插件的 js
Remove comments icon from WordPress admin bar
function wpdevil_admin_bar_render() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('comments');
//$wp_admin_bar->add_menu( array( 'parent' => 'new-content','id' => 'new_media','title' => __('Media'),'href' => admin_url( 'media-new.php')) );
}
// and we hook our function via
add_action( 'wp_before_admin_bar_render', 'wpdevil_admin_bar_render' );
Remove widgets from WordPress dashbord
//clear Dashboard
function wpdevil_remove_dashboard_widgets() {
global $wp_meta_boxes;
unset($wp_meta_boxes['dashboard']['normal']['high']['dashboard_browser_nag']);
//unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
// Side Column:
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}
add_action('wp_dashboard_setup', 'wpdevil_remove_dashboard_widgets' );
Remove version tail form css and js for proper caching.
## remove version from css and js for proper caching
function _remove_script_version( $src ){
if( is_admin() ) return $src;
if ( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
//if you wanna remove domain base even
return str_replace( site_url(), '', $src);
}
add_filter( 'script_loader_src', '_remove_script_version', 9999);
add_filter( 'style_loader_src', '_remove_script_version', 9999);
Comments are closed.