When it involves website performance, every byte and millisecond count.

WordPress core isn’t heavy, but the themes, plugin you enjoy may hamper the general page load time. There are many techniques to speed up your WordPress website.

For example

  1. Choose a best and reliable hosting
  2. Using CDN (Content Delivery Network)
  3. Leveraging browser & server caching
  4. Hosting on performance-optimized server
  5. Using a lightweight theme

Note:

Always choose a fast web hosting for better load time. As I already mention hosting is really very important for website speed.

After trying most of the hosting service I found Hostinger and Bluehost is the best hosting at low cost. Try this for better performence

Did you know there are many things included in the WordPress core which you may not use it and take necessary action on them may cut down few bytes to load the website faster.

The following steps can be done in two ways, first, by using some plugins and second, by adding few lines of code in functions.php (It is located under theme folder). I prefer the second way because once you install some plugin then it will come up unnecessary files.

Best Practice:

  1. Take a backup of the file you are going to modify, so if something goes wrong, you can upload your old file.
  2. Once you change the code then always check your website, whether it is opening or not. If you saw something wrong, then remove the code and re-check your site.

At first test your website in google page speed or gtmetrix or pingdom. Then add these codes

All the below codes to be added in functions.php unless specified differently.

1.  Remove Query Strings

If you checked your website in some website checker tools for load time, then you might saw recommendation to eliminate query strings from static resources (CSS, JS files). If the query  is available in the files then it may cause CDN not to cache the files; hence you may not be utilizing all caching benefits provided. To remove the query strings, add the following code.

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. Remove RSD Links

RSD (Really Simple Discovery) is needed if you intend to use XML-RPC client, pingback, etc. However, if you don’t need pingback or remote client to manage post then get rid of this unnecessary header by adding the following code.

remove_action( 'wp_head', 'rsd_link' ) ;

3.  Disable Emoticons

Remove extra code related to emojis from WordPress which was added recently to support emoticons in an older browser.

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' );

4.  Remove Short link

Starting from version 3, WordPress added short link (shorter link of web page address) in header code. For ex:

<link rel='shortlink' href='https://digitaluttam.com/?p=174' />

If not using short link for any functionality, then you can remove them by adding below.

remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);

5. Disable Embeds

WordPress introduced oEmbed features in 4.4 which allows any site to embed WordPress post remotely .

By adding the following code, it will prevent others from embedding your blog post and disable loading related JS file.

function disable_embed(){
wp_dequeue_script( 'wp-embed' );
}
add_action( 'wp_footer', 'disable_embed' );

6. Disable XML-RPC

Do you have a requirement to use WordPress API (XML-RPC) to publish/edit/delete a post, edit/list comments, upload file? Also having XML-RPC enabled and not hardened properly may lead to DDoS & brute force attacks.

If you don’t need then disable it by adding below.

add_filter('xmlrpc_enabled', '__return_false');

7. Hide WordPress Version

Although it does not help in performance but more to mitigate information leakage vulnerability.
By default, WordPress adds meta name generator with the version details which is visible in source code and HTTP header.

To remove the WP version, add below code.

remove_action( 'wp_head', 'wp_generator' ) ;

8. Remove WLManifest Link

Do you use tagging support with Windows live writer? If not remove it by adding below.

remove_action( 'wp_head', 'wlwmanifest_link' ) ;

9. Remove JQuery Migrate

WordPress added JQuery migration from version 3.6. This is not needed if you are using the latest version of JQuery and themes/plugin are compatible with it. To remove jquery-migrate.min.js from loading, add below code.

function deregister_qjuery() { 
 if ( !is_admin() ) {
 wp_deregister_script('jquery');
 }
} 
add_action('wp_enqueue_scripts', 'deregister_qjuery');

10. Disable Self Pingback

I don’t know why peoples need the self-pingback details on their blog post and I know it’s annoying. If you are too then below code will help.

function disable_pingback( &$links ) {
 foreach ( $links as $l => $link )
 if ( 0 === strpos( $link, get_option( 'home' ) ) )
 unset($links[$l]);
}
add_action( 'pre_ping', 'disable_pingback' );

11. Disable or Limit Post Revisions

In WordPress post revisions are not new and it is helpful to restore the post if browser crash or lose the network. But do you really need each and every time? ask yourself

By default, WordPress stores every single changes you make in your post or page and it will bloat the database. You may disable it entirely or limit the number of revisions to be saved.

Add the following in wp-config.php file

To disable post revisions

define('WP_POST_REVISIONS', false);

To limit the number

Let’s say limit to keep max two revisions

define('WP_POST_REVISIONS', 2);

12. Disable Heartbeat

WordPress use heartbeat API to speak with a browser to a server by frequently calling admin-ajax.php. this might hamper the general page load time and increase CPU utilization if on shared hosting.

you can disable it by adding below.

add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}

13. Disable Dashicons on Front-end

Dashicons are utilized within the admin console, and if not using them to load any icons on front-end then you’ll want to disable it.

Adding below, dashicons.min.css will stop loading on front-end.

function wpdocs_dequeue_dashicon() {
        if (current_user_can( 'update_core' )) {
            return;
        }
        wp_deregister_style('dashicons');
}
add_action( 'wp_enqueue_scripts', 'wpdocs_dequeue_dashicon' );

14. Disable Contact Form 7 JS/CSS

If you are using Contact Form 7 then you might have noticed that their css/JavaScript files are getting loaded in every page. Well you are not alone

The best part is you can stop loading it with below code

add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );

15. enable browser cache

Having a caching system is very useful for returning visitor. You can enable caching system in your website without installing plugins.

Adding below code in your .htaccess file will enable cache system

<IfModule mod_expires.c>
# BEGIN Expire headers
ExpiresActive On
ExpiresDefault “access plus 5 days”
ExpiresByType image/x-icon “access plus 1 month”
ExpiresByType image/jpeg “access plus 1 month”
ExpiresByType image/png “access plus 1 month”
ExpiresByType image/gif “access plus 1 month”
ExpiresByType application/x-shockwave-flash “access plus 1 month”
ExpiresByType text/css “access plus 1 month”
ExpiresByType text/javascript “access plus 1 month”
ExpiresByType application/javascript “access plus 1 month”
ExpiresByType application/x-javascript “access plus 1 month”
ExpiresByType text/html “access plus 600 seconds”
ExpiresByType application/xhtml+xml “access plus 600 seconds”
# END Expire headers
# BEGIN Cache-Control Headers
<filesMatch “\.(ico|jpe?g|png|gif|swf)$”>
Header set Cache-Control “public”
<filesMatch “\.(css)$”>
Header set Cache-Control “public”
<filesMatch “\.(js)$”>
Header set Cache-Control “private”
<filesMatch “\.(x?html?|php)$”>
Header set Cache-Control “private, must-revalidate”
# END Cache-Control Headers
</IfModule>

16. enable Gzipping

If you compress your whole website data into ZIP format, then it will load quickly on your browser. You can enable this by adding this simple code into your PHP.INI file. Search for this line

zlib.output_compression = Off

Change the word “Off” to “On”.
Now search for this line

zlib.output_compression_level = 6

The level “#” you currently have will more than likely be different. Set it to the number 6 as shown above. Save your file and make sure your website is still working correctly. You should be able to see an increase of speed of your website.

17. Database optimization

Database is important for every website. And WordPress stores unnecessary files in your database. For example, if you install a plugin and after few days you delete the plugin for some reason but plugin data is still stored in the database even after deleting the plugin. In that cast just go to your database and locate that plugin table and delete that.

Conclusion

Above will help you to reduce your website load time and increase performance. And obviously you can do all that with help of plugin. But at the same time plugin will generate extra code in your database. So it is good practice to change all these manually

Leave a Reply