Last active
September 30, 2018 07:00
-
-
Save crewstyle/aae510e3874010bcbf695c8cd4f9483e to your computer and use it in GitHub Desktop.
WordPress ~ Clean head HTML tag - #frontend #optimisation
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
<?php | |
/** | |
* Define what to clean from the theme header frontend, via the "remove_action" hook. | |
* | |
* @see https://github.com/GetOlympus/Zeus-Core | |
*/ | |
$optims = [ | |
'adjacent_posts_rel', // Removes the next and previous post links from the header | |
'feed_links', // Removes Automatics RSS links, which will still work with your own links | |
'shortlink', // Removes the shortlink url from header | |
'recent_comments', // Removes a block of inline CSS used by old themes from the header | |
'resource_hints', // Removes dns-prefetch links from the header | |
'index_rel_link', // Removes rel navigation links | |
'parent_post_rel_link', // Removes rel parent link | |
'rest_output_link_wp_head', // Removes REST API link tag | |
'rsd_link', // Removes Really Simple Discovery (RSD) links used for automatic pingbacks | |
'start_post_rel_link', // Removes rel first post link | |
'wc_generator_tag', // Removes WooCommerce meta generator tag | |
'wp_dlmp_l10n_style', // Removes i18n styles | |
'wp_generator', // Removes WordPress meta generator tag | |
'wlwmanifest_link', // Removes the link to wlwmanifest.xml needed to support Windows Live Writer | |
]; | |
// Iterate on all optimizations | |
foreach ($optims as $key) { | |
if ('adjacent_posts_rel' === $key) { | |
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); | |
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); | |
continue; | |
} | |
if ('feed_links' === $key) { | |
remove_theme_support('automatic-feed-links'); | |
remove_action('wp_head', 'feed_links', 2); | |
remove_action('wp_head', 'feed_links_extra', 3); | |
continue; | |
} | |
if (in_array($key, ['parent_post_rel_link', 'start_post_rel_link'])) { | |
remove_action('wp_head', $key, 10, 0); | |
continue; | |
} | |
if ('shortlink' === $key) { | |
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); | |
remove_action('template_redirect', 'wp_shortlink_header', 11, 0); | |
continue; | |
} | |
if ('recent_comments' === $key) { | |
add_filter('show_recent_comments_widget_style', '__return_false'); | |
continue; | |
} | |
if ('resource_hints' === $key) { | |
remove_action('wp_head', 'wp_resource_hints', 2); | |
continue; | |
} | |
// Default action | |
remove_action('wp_head', $key); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment