-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-speed-optimization.php
More file actions
35 lines (30 loc) · 1.08 KB
/
wp-speed-optimization.php
File metadata and controls
35 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/**
* Plugin Name: WP Speed Optimization
* Description: A set of performance tweaks for WordPress.
* Author: Mahmood Saeed
* Author URI: https://www.linkedin.com/in/mahmood-saeed/
*/
// Disable emojis
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
// Remove query strings
function remove_query_strings($src) {
if(strpos($src, '?ver='))
$src = remove_query_arg('ver', $src);
return $src;
}
add_filter('script_loader_src', 'remove_query_strings', 15, 1);
add_filter('style_loader_src', 'remove_query_strings', 15, 1);
// Clean up WordPress head
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
// Lazy-load images (native)
add_filter('wp_lazy_loading_enabled', '__return_true');
// Database cleanup (on activation)
register_activation_hook(__FILE__, function() {
global $wpdb;
$wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'");
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_%'");
});