Created
January 14, 2019 19:46
-
-
Save w-jerome/43b228201d3c014543ccc01343b29d4e to your computer and use it in GitHub Desktop.
WordPress - Theme Clean Up
This file contains hidden or 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 | |
/* ================================================================ | |
* Clean up functions | |
* Remove & clean all the stuff added by wordpress | |
* ================================================================ */ | |
/** | |
* WP Theme Clean Up | |
*/ | |
if (! function_exists('wp_theme_start_cleanup')) { | |
function wp_theme_start_cleanup() | |
{ | |
// Launching operation cleanup. | |
add_action('init', 'wp_theme_cleanup_head'); | |
// Remove WP version from RSS. | |
add_filter('the_generator', 'wp_theme_remove_version'); | |
// Remove Wordpress version from css | |
add_filter('style_loader_src', 'wp_theme_remove_version_css_js', 9999); | |
// Remove Wordpress version from js | |
add_filter('script_loader_src', 'wp_theme_remove_version_css_js', 9999); | |
// Remove login error message | |
add_filter('login_errors', 'wp_theme_no_wordpress_errors'); | |
// remove emoji stuff | |
add_action('init', 'wp_theme_disable_wp_emojicons'); | |
} | |
} | |
/** | |
* Clean up all the useless stuff added in <head> by Wordpress | |
*/ | |
if (!function_exists('wp_theme_cleanup_head')) { | |
function wp_theme_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); | |
// Outputs the REST API link tag | |
remove_action('wp_head', 'rest_output_link_wp_head', 10); | |
// Link header for the REST API | |
remove_action('template_redirect', 'rest_output_link_header', 11, 0); | |
// oEmbed discovery links | |
remove_action('wp_head', 'wp_oembed_add_discovery_links', 10); | |
// WP version. | |
remove_action('wp_head', 'wp_generator'); | |
} | |
} | |
/** | |
* Supprime la version de WordPress dans la balise meta generator | |
*/ | |
if (!function_exists('wp_theme_remove_version')) { | |
function wp_theme_remove_version() | |
{ | |
return ''; | |
} | |
} | |
/** | |
* Supprime la version de WordPress dans les appels CSS/JS | |
*/ | |
if (!function_exists('wp_theme_remove_version_css_js')) { | |
function wp_theme_remove_version_css_js($src) | |
{ | |
if (strpos($src, 'ver=')) { | |
$src = remove_query_arg('ver', $src); | |
} | |
return $src; | |
} | |
} | |
/** | |
* Désactive les messages d’erreur de connexion | |
*/ | |
if (!function_exists('wp_theme_no_wordpress_errors')) { | |
function wp_theme_no_wordpress_errors() | |
{ | |
return 'Something is wrong!'; | |
} | |
} | |
/** | |
* Disable emojis | |
*/ | |
if (!function_exists('wp_theme_disable_wp_emojicons')) { | |
function wp_theme_disable_wp_emojicons() | |
{ | |
remove_action('admin_print_styles', 'print_emoji_styles'); | |
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_filter('wp_mail', 'wp_staticize_emoji_for_email'); | |
remove_filter('the_content_feed', 'wp_staticize_emoji'); | |
remove_filter('comment_text_rss', 'wp_staticize_emoji'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment