Last active
October 20, 2018 06:27
-
-
Save almone/5c7da2870a720df52247 to your computer and use it in GitHub Desktop.
Clean wp_head from junk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Clean wp_head from junk | |
add_action('after_setup_theme', 'start_cleanup'); | |
function start_cleanup() { | |
// Initialize the cleanup | |
add_action('init', 'cleanup_head'); | |
} | |
// WordPress cleanup function | |
function cleanup_head() { | |
remove_action('wp_head', 'rsd_link'); // EditURI link | |
remove_action('wp_head', 'feed_links_extra', 3); // Category feed links | |
remove_action('wp_head', 'feed_links', 2); // Post and comment feed links | |
remove_action('wp_head', 'wlwmanifest_link'); // Windows Live Writer | |
remove_action('wp_head', 'index_rel_link'); // Index link | |
remove_action('wp_head', 'parent_post_rel_link', 10, 0); // Previous link | |
remove_action('wp_head', 'start_post_rel_link', 10, 0); // Start link | |
remove_action('wp_head', 'rel_canonical', 10, 0); // Canonical | |
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); // Shortlink | |
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); // Links for adjacent posts | |
remove_action('wp_head', 'wp_generator'); // WP version | |
// remove_action('wp_head', array(visual_composer(), 'addMetaData')); // Visual Composer | |
} | |
// Remove Slider Revolution meta tag | |
add_filter('revslider_meta_generator', 'remove_revslider_meta_tag'); | |
function remove_revslider_meta_tag() { | |
return ''; | |
} | |
// Remove All Yoast HTML Comments | |
// https://gist.github.com/paulcollett/4c81c4f6eb85334ba076 | |
if (defined('WPSEO_VERSION')){ | |
add_action('get_header',function (){ ob_start(function ($o){ | |
return preg_replace('/\n?<.*?yoast.*?>/mi','',$o); }); }); | |
add_action('wp_head',function (){ ob_end_flush(); }, 999); | |
} | |
// Remove version param from any enqueued scripts | |
function remove_wp_ver_css_js( $src ) { | |
if ( strpos( $src, 'ver=' ) ) | |
$src = remove_query_arg( 'ver', $src ); | |
return $src; | |
} | |
add_filter( 'style_loader_src', 'remove_wp_ver_css_js', 9999 ); | |
add_filter( 'script_loader_src', 'remove_wp_ver_css_js', 9999 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment