The following 6 code snippets are really simple to implement and will take you less than 5 minutes to render your WordPress blog current faster! The first 5 can be pasted into your theme's functions.php file for a quick fix. Number 6 would go into your site's wp-config.php file, but this is another simple copy/paste solution to give your WordPress site a speed boost. If you want to speed up WordPress even more, you will have some additional tips (links), but these may take a little longer to implement.

1 - Remove string queries from static resources

Getting rid of query strings on your css and js files not only allows you to cache these static files, but also gives your Google Pagespeed score a boost.

/ * Remove Query Strings from Static Resources / ***************************************** *************** / function remove_cssjs_ver ($ src) {if (strpos ($ src, '? Ver =')) $ src = remove_query_arg ('ver', $ src); Return $ src; } Add_filter ('style_loader_src', 'remove_cssjs_ver', 10, 2); Add_filter ('script_loader_src', 'remove_cssjs_ver', 10, 2);

2 - Delete emoji files

Since WordPress 4.2, they introduced emojis. This has added a lot of javascript code only to add the possibility of making smileys in your articles and comments. It's inflated and useless for those who do not use it, so it's fair enough to get rid of it (disable). Some lines will not be essential.

/ * Remove Emoji included files since they will not be used / ************************************* ******************* / function disable_wp_emojis () {// all actions related to emojis remove_action ('admin_print_styles', 'print_emoji_styles'); // not necessary 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'); // not necessary remove_filter ('wp_mail', 'wp_staticize_emoji_for_email'); // not necessary remove_filter ('the_content_feed', 'wp_staticize_emoji'); Remove_filter ('comment_text_rss', 'wp_staticize_emoji'); // filter to remove TinyMCE emojis add_filter ('tiny_mce_plugins', 'disable_emojicons_tinymce'); } Add_action ('init', 'disable_wp_emojis'); // disable tinyMCE emojicons function function disable_emojicons_tinymce ($ plugins) {if (is_array ($ plugins)) {return array_diff ($ plugins, array ('wpemoji')); } Else {return array (); }} // remove DNS prefetch add_filter ('emoji_svg_url', '__return_false');

3 - Delete javascript code from default comments

If you are not using comments on your site, there is no reason to upload this code. The “comment-reply.js” file is loaded on all your pages, even if you have comments disabled in your wordpress dashboard settings. You can use the code snippet below to disable this.

/ * Delete the comment in the default codes **************************************** ***************** / function speed_clean_header_hook () {wp_deregister_script ('comment-reply'); } add_action ('init', 'speed_clean_header_hook');

If you configure a new website and consider having the comments, you probably need to redeem it to use Disqus and the universal code they provide. This will allow the page to load faster and provide a better user experience. The management of comments will be done outside your website. You can use the WordPress version to keep control of comments from your dashboard, although we realized that this overloads your database. data unnecessarily.

4 - Remove loading of embedded content

The wp_embed.js file is what allows you to embed content from tweets, youtube videos, and other posts directly into your post just using the url. Some may find this useful if they use this regularly and can't be shy about using a embed code, for those who don't need it. So, we are going to deactivate it!

/ * Delete embedding content ******************************************** ************* / function speed_stop_loading_wp_embed () {if (! is_admin ()) {wp_deregister_script ('wp-embed'); }} add_action ('init', 'speed_stop_loading_wp_embed');

5 - Configure the heartPress functionality of WordPress

WordPress Heartbeat can be useful if you have a lot of people on the dashboard who often make edits, but if you're the only one working on your site, you don't have to. If you want to disable it entirely, you can use the first snippet below. Just be aware that other plugins can catch on to the heartbeat to perform certain functions and disabling it entirely could prevent those functions from performing.

/ * Disable heatbeat ********************************************* ************ / add_action ('init', 'stop_heartbeat', 1); function stop_heartbeat () {wp_deregister_script ('heartbeat'); }

I usually use this second code snippet below that keeps the heartbeat active for people who edit pages and posts because I expected the most overlap between users. The second function here simply slows down the heartbeat to run every 60 seconds. You can modify this in several ways to change the heart rate and change the pages it runs on. You can also exclude the filter or the action hook. If you only want to change the frequency, for example, you just need to add the filter hook and its corresponding function.

/ * Configure the heatbeat ********************************************** ************ / // Remove the heatbeat add_action ('init', 'stop_heartbeat', 1); function stop_heartbeat () {global $ pagenow; if ($ pagenow! = 'post.php' && $ pagenow! = 'post-new.php') wp_deregister_script ('heartbeat'); } // Limit the heatbeat function heartbeat_frequency ($ settings) {$ heartbeat_frequency = 60; // 60 seconds max $ settings ['interval'] = $ heartbeat_frequency; return $ settings; } add_filter ('heartbeat_settings', 'heartbeat_frequency');

6 - Remove or Limit Revisions

Article revisions are automatically saved by default, but you may not need to keep as many revisions or want to stop saving them altogether. This frees up space in the database. data. With fewer saved revisions you will have more inactivity in your database. data. This modification should be made in your “wp-config.php” file. In the code snippet below I show how to disable revisions, and also how to limit the number of revisions. You will choose what suits you.

Change Post Revision Save Settings // Remove revivions define ('WP_POST_REVISIONS', FALSE); // Limit revisions define ('WP_POST_REVISIONS', 3);

These are your 6 ways to speed up WordPress in under 5 minutes. I bet it took you longer to read this post than it did to implement the changes.

Some useful tutorials in blog optimization

That's all, if you have any questions, do not hesitate.