Every byte and millisecond counts when it comes to website performance.
Plugins and themes you use might affect how long it takes for a page to load. Your WordPress website can be speed up using a variety of methods by these 14 method you can solve this problem.
For instance:
- Using a CDN (Content Delivery Network)
- Taking Advantage of Cached Data from the Browser and the Server
- The use of a high-performance server
- Using a thin theme
As a matter of fact, there are numerous features in WordPress core that you may not use, and taking action on them could help your website load faster.
First, you may use a plugin to accomplish this, or you can just add a few lines of code to your functions.php.
- Advertisement -
As a rule, I avoid using plugins wherever possible, unless it’s absolutely necessary.
Optimal Procedures
In the event that everything goes awry, you’ll have an easy way to go back in time.
Unless otherwise noted, all of the following codes should be added to functions.php.
- Advertisement -
- Get Rid of Query Strings
If you’ve done any load time testing on your website, you’ve probably run across a suggestion to remove query strings from static resources (CSS, JS files).
The CDN may not cache your files if they contain query strings; as a result, you may not be taking advantage of all the caching benefits available.
Add the following code to remove the query strings.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 ); - Remove all references to RSD
If you want to use XML-RPC client, pingback, etc., you’ll require RSD (Really Simple Discovery). As an alternative to this superfluous header, you may simply remove it by inserting the following code.
remove_action( 'wp_head', 'rsd_link' ) ;
- Deactivate Emoticons
A recent addition to WordPress to enable emojis in outdated browsers should be removed.
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’ );- Advertisement -
- Remove the link to the short URL.
The shortlink (shorter URL for a web page) was added to the header code in WordPress. The following code can be used to remove any shortlinks that are no longer needed.
remove_action(‘wp_head’, ‘wp_shortlink_wp_head’, 10, 0); - Stop Embedding
oEmbed functionalities were introduced in WordPress 4.4, allowing any site to embed WordPress posts remotely. In order to stop your blog post from being embedded and to disable the loading of relevant JS files, add the following code to your article.
function disable_embed()
{ wp_dequeue_script( ‘wp-embed’ ); }
add_action( ‘wp_footer’, ‘disable_embed’ ); - XML-RPC should be disabled.
Do you need to publish, amend, or delete a post, update or list comments, or submit a file using the WordPress API (XML-RPC)? DDoS and brute force attacks can occur if XML-RPC is enabled but not properly protected. Add below to disable it if you don’t want.
add_filter(‘xmlrpc_enabled’, ‘__return_false’); - Hide the WordPress Version
This does not improve performance, but rather reduces the risk of information leaking. In the source code and in the HTTP header, WordPress includes a meta name generator with the version information.
Add the following code to get rid of the WP version.
remove_action( ‘wp_head’, ‘wp_generator’ ) ; - Remove the link to WLManifest
Do you make use of Windows Live Writer’s tagging capabilities? If this is the case, then delete it by adding the following.
remove_action( ‘wp_head’, ‘wlwmanifest_link’ ) ; - Removing and migrating JQuery
Version 3.6 of WordPress brought JQuery migration to the platform. As long as you’re using the most recent version of JQuery, this isn’t necessary. Add the following code to prevent jquery-migrate.min.js from being loaded to prevent it from being used.
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px ‘Helvetica Neue’; min-height: 15.0px} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px ‘Helvetica Neue’}
function deregister_qjuery() {
if ( !is_admin() ) { wp_deregister_script(‘jquery’); } }
add_action(‘wp_enqueue_scripts’, ‘deregister_qjuery’); - Self-Pingback is disabled.
Your blog post’s self-pingback elements annoy me, and I’m sure it’s not just me. Here’s some code that can help if you’re one of them.
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’ ); - Post Revisions can be disabled or limited.
If the browser crashes or the network is down, post modifications in WordPress are helpful in regaining access to the content. However, how many times have you seen this happen?
In WordPress, by default, the database gets bloated by saving revisions for each post that is drafted or published. You have the option of limiting the number of revisions saved or completely disabling this feature.
Add the following in wp-config.php file
Disabling post-revisions
define(‘WP_POST_REVISIONS’, false);
Limiting the revisions:
define(‘WP_POST_REVISIONS’, 2); - Stopping the heartbeat
By frequently contacting admin-ajax.php, WordPress communicates with a browser and a server. If you’re using shared hosting, this could slow down the total page load time and increase CPU utilisation.
You can turn off the heartbeat API if you don’t need it by adding the code below.
add_action( ‘init’, ‘stop_heartbeat’, 1 );
function stop_heartbeat() {
wp_deregister_script(‘heartbeat’);
} - On the front-end, disable Dashicons.
If you’re not using Dashicons to load any front-end icons, you may wish to turn them off in the admin console. dashicons.min.css will no longer load on the front end if the code below is added.
function wpdocs_dequeue_dashicon() {
if (current_user_can( ‘update_core’ )) {
return; }
wp_deregister_style(‘dashicons’);
}
add_action( ‘wp_enqueue_scripts’, ‘wpdocs_dequeue_dashicon’ ); - Turn off the Contact Form 7 plugin.
Use Contact Form 7 and notice their CSS/JavaScript files being loaded on each page? Contact Form 7 users: You’re not the only one who feels this way.
To your relief, the code provided below prevents it from loading.
add_filter( ‘wpcf7_load_js’, ‘__return_false’ );
add_filter( ‘wpcf7_load_css’, ‘__return_false’ );
Conclusion
A few HTTP requests and the size of the page will be reduced as a result of the above. On Github, you can find all of the source code. Check out WP Rocket if you’re seeking a premium caching and performance-enhancing plugin.
To get such kind of blog you can check our more blogs