I often get an earful from people about how bloated WordPress is when I tell them how much I love and use it. This post is going to share a quick tip on how to cut of the fat that WordPress adds to the a site’s markup.

It’s true. If you were to download and install WordPress right out of the box, activate the default TwentyFourteen theme, then view the page source, you would see a crap-tastic amount of markup in the page head. I’m not even going to publish an example of that markup because it’s so freaking big, but you can view the TwentyFourteen source for yourself.

OK, WordPress lovers and haters alike agree that there’s some bloat going on. If speedy webpage performance is a real goal these days, then how do we clean this up?

Enter the remove_action() function for the rescue! This handy little snippet allows you to hook into the WordPress wp_head action and alter the default behavior without touching core. The following example is what I use to remove many of the default markup that WordPress adds to . Note this is what I use personally, but you may want to evaluate what your needs are and adjust accordingly. There are also a ton of other filters to play with, so this just gives you an idea of what’s possible.

You can add this to your functions.php file, but I’m a big fan of splitting functions up into separate files and importing them into functions.php using require_once().

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 );

  // Canonical
  remove_action('wp_head', 'rel_canonical', 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' );

}

This is just one way to remove some of the bloat that comes in WordPress. It’s great, but not a silver bullet. In other words, it helps but it’s just one piece in the big puzzle that is optimizing our sites for better performance.

WordPress

Subscribe to Devigner Digest

I read a lot of crap about design and development and 90% really is crap. Subscribe and I will send links to the other 10% about once a month.