increase WordPress website speed

WordPress websites at their core are based on a slick and fast framework, there’s a reason WordPress powers about 35-40% of the internet. With extensive design and functionality options comes the possibility of slow performance. 

Studies show that you have around 7 seconds to capture a user’s attention, therefore every second there is a delay in your website loading eats into valuable time which you have to make an impression on. 

It’s not only the user experience that is affected, search engines such as Google use load speed as a metric for page ranking. The slower your load speed, the lower the search results from your website will likely appear and ultimately hinder your traffic.  

google page speed score 100/100

If you haven’t already, we recommend you check out our previous article on how to speed up your website loading time. This previous article focuses more on plugins to aid website speed, whereas we’re now focusing on what you can do without a plugin, getting down to the core essentials of website speed and giving you the knowledge to optimize your site using code. 

First things first though, make a backup of your website. If something should go wrong, you need to be able to roll back on the changes you’ve made.  This should apply whenever you update your website, but it is especially important here as you will be changing the code. 

IMPORTANT: Unless otherwise specified all of the codes detailed below should be added to the functions.php file. To access this file, click on Appearance -> Theme Editor, then the functions.php file can be accessed from the right-sidebar

1. Remove RSD Links

RSD stands for Really Simple Discovery, this is a link placed in the header and is used for connecting third-party software to your website to publish blogs. If you’re not using third-party software that utilizes this feature, you can remove these links from your website. 

To remove this header, add the following code to your WordPress website.

remove_action( ‘wp_head’, ‘rsd_link’ ) ;

2. Remove Emoji

WordPress has code added to support Emoticons in older browsers, unless you use emojis heavily on your website, we would recommend removing this. 

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

3. Remove the Short link

WordPress includes a short link feature, this is so you can copy a short link for your WordPress website pages to facilitate easy sharing of your website or blog. If you don’t utilize these links or use another short link system like bit.ly, get rid of the built-in short links. 

Here is the code to remove the short link: 

remove_action(‘wp_head’, ‘wp_shortlink_wp_head’, 10, 0);

4. Disable Contact Form 7

Running contact form 7 means the forms CSS & JavaScript files are being loaded on every page. This increases the load time of your website. If you’re not using this feature, these should be disabled.

You can prevent this from occurring with the below code. 

add_filter( ‘wpcf7_load_js’, ‘__return_false’ );

add_filter( ‘wpcf7_load_css’, ‘__return_false’ );

5. Disable Post Revisions

Post revisions allow you to revert to an earlier version of a post or page by continually saving temporary revisions every 60 seconds. But in reality, how often have you had to revert your pages, that’s a lot of memory taken up for a barely used feature. You can disable the feature or set a limit on how many revisions get saved. Perhaps leave this enabled when initially creating your site or making any major updates, but for ongoing maintenance, you’re taking up a lot of memory for a function you’re not using. 

To disable post revisions, the following should be added to the wp-config.php file

  • Disable post revisions 

define(‘WP_POST_REVISIONS’, false);

  • Limit the number of saved revisions

define(‘WP_POST_REVISIONS’, 2);

This example will limit to 2 revisions, to amend this just replace the number 2 with the number of revisions you would like to save. 

IMPORTANT: This should be placed above the ABSPATH line, otherwise it will not work. 

6. Disable Heartbeat API 

WordPress Heartbeat API is an API that uses AJAX calls to allow a browser to communicate with your server. This facilitates functions like auto-saving posts as it allows continuous communication between your browser and the server. Each time the API is used, the server CPU is used which can slow down your performance. 

Get a quote

To disable the API, use the below code.

add_action( ‘init’, ‘stop_heartbeat’, 1 );

function stop_heartbeat() {

wp_deregister_script(‘heartbeat’);

}

7. Disable Dashicons

Dashicons is the official WordPress icon font. If you don’t use these icons on your front end, then these can be disabled. The below should be added to the dashicons.min.css file. 

function wpdocs_dequeue_dashicon() {

        if (current_user_can( ‘update_core’ )) {

            return;

        }

wp_deregister_style(‘dashicons’);

}

add_action( ‘wp_enqueue_scripts’, ‘wpdocs_dequeue_dashicon’ );

8. Disable Pingbacks 

Pingbacks are an archaic function in WordPress that were used for blogs to notify each other about links. If you post an article with a link to another blog, the other blog will be notified of the link. This is a largely redundant function which can in most cases be disabled by the below code. 

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

9. Remove the WLManifest Link

If you don’t use Windows Live writer, this can be removed, simply add the below to remove it. There are no security vulnerabilities with this file as there are in the XML RPC file, the removal of this file is purely for optimization. 

remove_action( ‘wp_head’, ‘wlwmanifest_link’ ) ;

10. Disable XML RPC WordPress API

XML RPC is used To standardize communication between WordPress and third-party applications. It was mainly used to publish blog posts and allow the mobile app to communicate to WordPress. There is a downside, as this API can expose vulnerabilities and leave you open to DDOS attacks. 

Simply add the below to disable this:

add_filter(‘xmlrpc_enabled’, ‘__return_false’);

11. Disable oEmbeds

oEmbeds enables you to embed HTML for your pages and posts onto other websites whilst retaining the style information. If you don’t use this feature as a part of your promotional strategy, you can disable it. 

The following code disables people from embedding your posts. 

function disable_embed(){

wp_dequeue_script( ‘wp-embed’ );

}

add_action( ‘wp_footer’, ‘disable_embed’ );

12. Remove Query Strings 

Removing query strings from static resources is beneficial as it prevents caching issues. URLs with a query string don’t get cached by some CDN’s (Content Delivery Network). CDN networks in simple terms are used to cache a version of your website, closer to the user, thus improving the delivery speed. If your CDN is not caching static objects because of a query string, the delivery speed of your website will most certainly be affected. 

The following code can be used to disable this: 

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

The above instructions can seem quite daunting, especially if you don’t have any previous experience working with code. If this sounds like you, I cannot stress how important it is to back up your website before undertaking any of these updates. 

Alternatively, you may wish to let the professionals handle this. WP Agents are here to help, we take care of the above points as standard when undertaking any of our managed WordPress packages. 

To speak to a member of our support team and to see what WP Agents can do for you, please fill out the following form and book a free consultation.

Related Post