How to optimize page speed and security on WP without plugins

JWQQQ

Junior Member
Joined
Oct 24, 2012
Messages
100
Reaction score
27
Here's some code snippets you can add to your functions.php file to increase security, remove footprints and increase page speed. There are plugins that do this stuff, but imo it's easier to avoid plugins and stick to code.


PHP:
//remove emojis
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );


PHP:
//remove login errors
add_filter('login_errors',create_function('$a', "return null;"));

PHP:
//remove junk code from the head
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'feed_links_extra', 3 );
remove_action('wp_head', 'feed_links', 2 );
remove_action('wp_head', 'parent_post_rel_link', 10, 0 );
remove_action('wp_head', 'start_post_rel_link', 10, 0 );
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);

Code:
//Remove query string from static resources, page speed

//Remove query string from static resources
function _remove_script_version( $src ){
    if ( strpos( $src, 'ver=' ) )
        $src = remove_query_arg( 'ver', $src );
    return $src;
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );


These four are the most important ones imo, but there's plenty more you can do. Source for the code: https://tobiesen.com/wordpress/
 
This should be the right way without using plugins.
 
Back
Top