Skip to content

Instantly share code, notes, and snippets.

@ianpegg
Last active July 20, 2024 13:25
Show Gist options
  • Save ianpegg/53842447a5016ad5d3eac073dd2390d5 to your computer and use it in GitHub Desktop.
Save ianpegg/53842447a5016ad5d3eac073dd2390d5 to your computer and use it in GitHub Desktop.
A lightweight way to improve performance by removing elements of WP core that we don't need.
<?php
/**
* Plugin Name: eggMUP: Performance
* Plugin URI: https://gist.github.com/ianpegg/53842447a5016ad5d3eac073dd2390d5
* Description: Optimise WP for performance by removing things we don't need.
* Version: 1.0.0
* Author: Ian Pegg
* Author URI: https://eggcupwebdesign.com
* php version 7.4.15
*
* @category Must_Use_Plugin
* @package WordPress_Plugin
* @author Ian Pegg <[email protected]>
* @license GNU/GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
* @link https://eggcupwebdesign.com
*/
namespace EggCup\MUP\Performance;
if (!defined('ABSPATH')) {
exit;
}
/**
* This script registers following functions with WP action hooks/filters:
*/
add_action('init', __NAMESPACE__ . '\\Cleanup_head');
add_action('init', __NAMESPACE__ . '\\Remove_emojis');
/**
* Removes all the cruft that WP core adds to the <head>.
*
* @return void
*/
function Cleanup_head()
{
add_filter('the_generator', '__return_false');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'wp_shortlink_wp_head', 10);
remove_action('wp_head', 'wp_oembed_add_discovery_links');
remove_action('wp_head', 'wp_oembed_add_host_js');
remove_action('wp_head', 'rest_output_link_wp_head', 10);
add_filter('use_default_gallery_style', '__return_false');
add_filter('show_recent_comments_widget_style', '__return_false');
}
/**
* Strip out this nonsense as most browsers support emojis these days
* anyway.
*
* @return void
*/
function Remove_emojis()
{
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_action('admin_print_styles', 'print_emoji_styles');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
if (!is_admin()) {
add_filter('emoji_svg_url', '__return_false');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment