Functions File Code That Removes Unnecessary WordPress Header Code

Posted Friday, April 20th, 2018 - 3,220 views

If you use WordPress, and want to clean the code bloat it generates in the header, or are removing unnecessary code from your WordPress site in order to increase page speed, you can add the following lines of code to your functions.php file.

As always, the advice will be to make sure to test your site

remove_action( 'wp_head', 'wp_resource_hints', 2 );
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
remove_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
remove_action('wp_head', 'wp_generator');
remove_action ('wp_head', 'rsd_link');
remove_action( 'wp_head', 'wlwmanifest_link');
add_filter( 'max_srcset_image_width', create_function( '', 'return 1;' ) );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );

Now, every WordPress install is different so you’ll want to make sure you’re not removing something your site may need. Make sure that you test your site after adding each line to make sure of which code is removed, and whether your site needs the code or relies on it for certain functions of performance reasons.

Also note, everyone has their own reasons for adding or removing code so some may not agree with the removal of any, or all of the above code from your header at all. If like to take full control of your header than the above code will work just fine for you.

Leave a Reply

Your email address will not be published. Required fields are marked *

©2024 First Planet

Studio
  • 2007 James St. 
    Burlington, ON, L7R 1H1
  • info@firstplanet.ca
  • 289-499-5934
Follow us