Skip to content

Instantly share code, notes, and snippets.

@marcelotorres
Last active November 24, 2016 12:52
Show Gist options
  • Save marcelotorres/9959e9fc42f6104acb780f35ad857e92 to your computer and use it in GitHub Desktop.
Save marcelotorres/9959e9fc42f6104acb780f35ad857e92 to your computer and use it in GitHub Desktop.
Remove unnecessary scripts and tags on WP frontend head
<?php
/*
* Remover scripts e tags desnecessários do head frontend do WP
*/
// Emojis
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
//RSD
remove_action('wp_head', 'rsd_link');
//Windows Live Writer
remove_action('wp_head', 'wlwmanifest_link');
//Versão do WP
remove_action('wp_head', 'wp_generator');
//Posts Relacionados
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');
// Admin Bar
add_filter('show_admin_bar', '__return_false');
//JSON API
function remove_json_api () {
// Remove the REST API lines from the HTML Header
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
// Remove the REST API endpoint.
remove_action( 'rest_api_init', 'wp_oembed_register_route' );
// Turn off oEmbed auto discovery.
add_filter( 'embed_oembed_discover', '__return_false' );
// Don't filter oEmbed results.
remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
// Remove oEmbed discovery links.
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
// Remove oEmbed-specific JavaScript from the front-end and back-end.
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
// Remove all embeds rewrite rules.
add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
}
add_action( 'after_setup_theme', 'remove_json_api' );
function disable_json_api () {
// Filters for WP-API version 1.x
add_filter('json_enabled', '__return_false');
add_filter('json_jsonp_enabled', '__return_false');
// Filters for WP-API version 2.x
add_filter('rest_enabled', '__return_false');
add_filter('rest_jsonp_enabled', '__return_false');
}
add_action( 'after_setup_theme', 'disable_json_api' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment