+917803057266

Home » Tips & Tricks » Clean the header section inserted by WordPress Core

Clean the header section inserted by WordPress Core

Are you looking for a solution to remove the extra code inserted by the WordPress core function wp_head()?

Then check the following codes and paste it in your themes functions.php file to make it work 🙂

1. Remove XML-RPC RSD link
remove_action ('wp_head', 'rsd_link');

 

2. Remove WordPress version number
function remove_header_version() {
return '';
}
add_filter('the_generator', 'remove_header_version');

 

3. Remove manifest link
remove_action( 'wp_head', 'wlwmanifest_link');

 

4. Remove shortlink
remove_action( 'wp_head', 'wp_shortlink_wp_head');

 

5. Remove query strings
function crunchify_cleanup_query_string( $src ){
$parts = explode( '?', $src );
//$parts = explode( '?ver', $src ); //use this when you want to remove only query string where ver written
return $parts[0];
}
add_filter( 'script_loader_src', 'clean_header_query_string', 15, 1 );
add_filter( 'style_loader_src', 'clean_header_query_string', 15, 1 );

 

6. Remove api.w.org
remove_action('wp_head', 'rest_output_link_wp_head', 10);
remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
remove_action('template_redirect', 'rest_output_link_header', 11, 0);