WordPress: rimuovere gli elementi superflui dall'header del tema

WordPress aggiunge molta marcatura ed informazioni non necessarie all'elemento head del nostro tema. Vediamo come ovviare a questo problema.

Aggiungete il seguente codice al file functionss.php:


add_action('init', 'my_head_cleanup');
add_filter('the_generator', 'my_rss_version');
add_filter( 'wp_head', 'my_remove_wp_widget_recent_comments_style', 1 );
add_action('wp_head', 'my_remove_recent_comments_style', 1);


function my_head_cleanup() {
	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', 'wp_generator' );                           

}

function my_remove_wp_widget_recent_comments_style() {
   if ( has_filter('wp_head', 'wp_widget_recent_comments_style') ) {
      remove_filter('wp_head', 'wp_widget_recent_comments_style' );
   }
}

function my_remove_recent_comments_style() {
  global $wp_widget_factory;
  if (isset($wp_widget_factory->widgets['WP_Widget_Recent_Comments'])) {
    remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
  }
}

function my_rss_version() { return ''; }
Torna su