Sarathlal N

Clean the page head - WordPress

In Default, WordPress print too many unnecessary data in its page head. We can simply clean up the page head by using a simple code snippet.

//Clean WordPress head
add_action('after_setup_theme','start_cleanup');

function start_cleanup() {
  // Initialize the cleanup
  add_action('init', 'cleanup_head');
}

// WordPress cleanup function
function cleanup_head() {
  // EditURI link
  remove_action( 'wp_head', 'rsd_link' );
  // Category feed links
  remove_action( 'wp_head', 'feed_links_extra', 3 );
  // Post and comment feed links
  remove_action( 'wp_head', 'feed_links', 2 );
  // Windows Live Writer
  remove_action( 'wp_head', 'wlwmanifest_link' );
  // Index link
  remove_action( 'wp_head', 'index_rel_link' );
  // Previous link
  remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
  // Start link
  remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
  // Shortlink
  remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
  // Links for adjacent posts
  remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
  // WP version
  remove_action( 'wp_head', 'wp_generator' );
}

Looking for a skilled WordPress/WooCommerce developer? I'm currently available for freelance, contract, or full-time remote opportunities! Let's create something amazing together. Send me a quick message, and I'll respond within 24 hours!

Recent Posts

  1. Understanding the Singleton Pattern and Using Traits to Achieve Singleton in WordPress Plugin Development
  2. REST API Methods Explained with Best Practices for Building Clean and Secure APIs
  3. My 28-Day Plan to Master Modern WordPress Development Using AI Tools
  4. Scaling WordPress - How Custom Database Tables Solve the Post Meta Bottleneck
  5. WordPress Transients Explained - A Developer's Guide to Site Performance

Your Questions / Comments

If you found this article interesting, found errors, or just want to discuss about it, please get in touch.