How to Add Expires Headers in WordPress
How to Add Expires Headers in WordPress

How to Add Expires Headers in WordPress

What Are Expires Headers?
Expires headers let you tell a visitor’s web browser whether it should load a given resource from the local browser cache or whether it needs to download a new version from the web server.

Let’s set a duration for the cached version of different file types before that file “expires” and the browser must download it from the server again.

Let’s say you want to control browser caching behavior for PNG image files on your site. If you set the Expires headers for PNG files equal to one month, a visitor’s browser will Load the already-downloaded version from the cache for one month after the initial access download.
Re-download that file from the server after one month.
You can set different Expires headers for different file types, which gives you granular control over your site’s browser cache.

How to Fix Add Expires Headers in WordPress
Now, let’s get into the actual how-to part and we’ll show you how to set up expired headers in WordPress

You can add expired headers for your WordPress site. You can do this either using your own code snippet at the server level or via some user-friendly WordPress plugins.

Read Also: What is Article Spinning? Will it help to SEO my Website?

Connect to your server using FTP in your preferred FTP client
Locate the .htaccess file in the root folder Download a backup copy of the .htaccess file to your local computer. That way, if anything goes wrong, you can reupload your backup copy to fix any potential problems.
Add the code snippet below near the top of the file:

ExpiresActive On
ExpiresByType image/jpg “access 1 year”
ExpiresByType image/jpeg “access 1 year”
ExpiresByType image/gif “access 1 year”
ExpiresByType image/png “access 1 year”
ExpiresByType image/svg “access 1 year”
ExpiresByType text/css “access 1 month”
ExpiresByType application/pdf “access 1 month”
ExpiresByType application/javascript “access 1 month”
ExpiresByType application/x-javascript “access 1 month”
ExpiresByType application/x-shockwave-flash “access 1 month”
ExpiresByType image/x-icon “access 1 year”
ExpiresDefault “access 2 days”


How to Add Expires Headers With a WordPress Plugin
If you don’t feel comfortable adding the expired headers code yourself, you can also find some WordPress plugins that can do the job for you. Some of these plugins add expire headers, while others use cache-control. Either way, the end result is that your WordPress site can benefit from browser caching.

One solution is to use a caching plugin if your host hasn’t already implemented caching for you. A great option here is WP Rocket. As soon as you activate the WP Rocket plugin, it automatically enables browser caching for you – there’s no need to configure any other settings.

Leave a Reply