Header Text - 2 Easy Ways to Add Expires Headers in WordPress

When you add expires headers in WordPress, it can assist your website to load faster. This is one way to speed up a
WordPress
website, as Expires Headers are simple instructions added to your website to tell a visitor’s browser how long it should keep certain files, like images or stylesheets, stored locally.

This is called browser caching, and it means your website loads faster because the browser doesn’t need to download the same files every time. This is especially helpful for websites with lots of repeat visitors.

For example, when someone revisits your WordPress website, their browser won’t have to re-download files like your logo or styles. This not only saves time but also reduces your server load. Plus, speed matters for search engines like Google. Websites that load quickly often rank higher in search results because Google wants to show users the best, most efficient sites.

So, one can say that adding expires headers is a simple way to enhance performance, improve your visitors’ experience, and boost your SEO rankings. Let’s learn how to add expires headers WordPress feature; users can implement this manually or by using plugins for better caching.

KEY TAKEAWAYS

  • Adding the expires headers in WordPress improves website speed by allowing browsers to store and reuse files like images, CSS, and JavaScript.
  • When you add expires headers, this reduces server load and improves user experience, especially for returning visitors.
  • You can set up expires headers in WordPress using a caching plugin for an easy and beginner-friendly solution.
  • Manual configuration via .htaccess or Nginx files provides advanced control over caching rules but requires technical knowledge.
  • Always back up your website before making changes to avoid potential issues.
  • Use tools like GTmetrix or browser developer tools to verify that the expires headers are working correctly.
  • Regularly check and revise your caching settings to match any changes in your website’s design or functionality.

What Are Expires Headers In WordPress?

Expires headers are simple rules added to your website that help improve its speed. They tell web browsers how long to keep specific files, like images, styles, or scripts, before updating them. Let’s show you an example.

When you visit a website, your web browser downloads files like images, CSS (the style of the site), and JavaScript (the interactive parts). These files help the website load properly. However, downloading them every time you visit can slow things down. That’s where browser caching comes in.

Now, how does browser caching (a.k.a client-side caching) work? Instead of downloading the same file repeatedly, your browser keeps a copy stored locally on your computer. When you revisit the WordPress site, the browser uses its stored version instead of downloading everything again. This makes the website load faster and saves internet bandwidth. However, how long should these files be stored locally?

Now, here’s where the expires headers play a key role. They act like instructions for your browser, telling it how long it can store certain files. For example:

  • Images: You can set them to stay in the browser cache for a year, as they rarely change.
  • CSS & JavaScript: These files may change more often, so you can set a shorter time, like a month or a few weeks.

With expires headers, your WordPress website doesn’t just load faster; it also reduces the workload on your server, making it more efficient for everyone visiting your site.

Cache-Control Headers vs Expires Headers WordPress Feature

Both expires headers and Cache-Control Headers help with browser caching, but they work differently. Expires headers use a fixed date in the future to tell browsers when to stop using the cached version of a file. For example, you can set an image file to expire on “January 1, 2026”.

However, cache-control headers are more modern and flexible. Instead of a fixed date, they use durations, like “cache this file for 1 year”. These headers can also include additional rules, like ensuring sensitive files are never cached.

While many websites use both for compatibility, the expires headers improve website speed effectively, especially if you’re new to browser caching.

Benefits of Expires Headers

The benefits of using expires headers are clear. First, they reduce server load because fewer requests are sent for the same files. This means your web server can handle more visitors without slowing down. Second, they lead to faster page load times for returning visitors.

Since their browsers already have the necessary files, the WordPress website loads quickly. Finally, this creates an improved user experience. Visitors enjoy browsing a quick, responsive website that keeps them engaged and happy.

When you add the expires headers WordPress option, you’re optimizing your site’s speed and ensuring it’s more efficient for your visitors and easier for your server to handle. It’s a small change with a big impact.

Before You Begin

Before you start learning how WordPress add expires headers, there are 2 important things to do:

  1. Back up your site.
  2. Check your hosting compatibility.

These steps ensure that you can make changes safely and effectively. We’ve already written detailed tutorials on how to back up a website that you can find at the following links:

How To Back up Your WordPress Site: A Comprehensive Guide

How to Export A WordPress Site: A Step-By-Step Guide

Optionally, you can also refer to the following to understand the role of website backups in maintaining security and SEO health:

The Role Of Backups In WordPress Hosting Security

The Role Of Website Backups In Maintaining SEO Health

However, to check hosting compatibility, ensure your hosting supports the necessary files and tools. It’s essential before making changes to your site’s configuration.

  • If your site uses Apache servers, check if you have access to the .htaccess file. This is where you’ll add the expires headers WordPress feature.
  • If your site is on Nginx, you’ll need access to its configuration file. Note that not all hosting providers allow this level of access, especially on shared hosting plans.

For the best experience, consider using performance-focused WordPress Hosting. These hosting providers are speed-optimized and often support advanced caching features like expires headers. They also offer better tools and support for managing your WordPress website’s performance.

By backing up your site and ensuring hosting compatibility, you’re setting yourself up for a smooth, problem-free process. Now, you’re ready to move on to adding those expires headers in WordPress.

How to Add Expires Headers in WordPress?

There are 2 ways to add expires headers WordPress feature:

  1. Use a WordPress Plugin
  2. Add Code Manually.

We typically recommend the first approach for beginners, as it’s straightforward. However, if you’re confident editing WordPress files, the second method is an excellent option.

Add Expires Headers with a WordPress Plugin

If you’re new to WordPress or want an easy way to add expires headers, using a caching plugin is the best option. This approach is also useful if hosting hasn’t implemented caching. There are multiple plugins that you can choose from:

  1. WP Rocket
  2. WP Super Cache
  3. W3 Total Cache
  4. WP Fastest Cache.

For this tutorial example, we use W3 Total cache, which makes the process simple and easy for beginners. They handle all the technical work, so you don’t need to worry about editing code. Here’s how to use it:

First, sign in to your WordPress Admin Dashboard. Go to Plugins Add New Plugin. Next, type W3 Total Cache in the Search Plugins search box. Once the W3 Total Cache plugin appears, click Install Now, then Activate to activate your plugin.

Add Expires Headers In WordPress -Install and Activate W3 Total Cache Plugin

After that, go to Performance Browser Cache from your WordPress dashboard. This section allows you to configure caching rules for your WordPress site. Check the box named Set expires header. This ensures the plugin adds expiration dates to your files.

Add Expires Headers In WordPress - Set Expires Headers in WordPress

Optionally, you can enable additional related settings to further enhance your website’s performance and caching flexibility. One way is to enable Set cache control header, which provides more precise control over how browsers cache your content. This setting ensures a balance between efficient caching and timely updates.

Add Expires Headers In WordPress -Set Cache-Control Header

Another useful setting is Enable HTTP (gzip) compression. By default, it’s enabled; however, if it’s not, enable it to reduce the size of your files, like HTML, CSS, and JavaScript. By minimizing file sizes, your WordPress website loads faster, improving user experience and reducing server load. 

Add Expires Headers In WordPress - Enable HTTP Gzip Compression

You can also mark the checkbox Prevent caching of objects after settings change. This ensures that whenever you update your files, such as images or scripts, the browser re-caches them properly. This avoids the risk of users seeing outdated content and helps maintain a seamless browsing experience. 

Add Expires Headers In WordPress - Enable Prevent Caching of Objects After Settings Change

These settings work together to optimize your WordPress site’s performance while ensuring that changes and updates are effectively reflected for users.

Additionally, if you scroll down, you can also configure caching for specific file types:

For instance, you can configure caching options for CSS and JavaScript:

Add Expires Headers In WordPress - Configure Caching for CSS and JavaScript

HTML and XML:

Add Expires Headers In WordPress - Enable HTML and XML Caching

Media files (images, icons, etc.):

Add Expires Headers In WordPress - Set Caching Settings for Media and Other Files

Once you’re done, click Save Settings in the top-right corner.

Boost your website’s performance by adding expires headers, allowing browsers to cache static files like images and CSS.
With Hosted.com’s WordPress Hosting solutions, you can trust that your site will load faster and provide a better user experience.

Manually Add Expires Headers WordPress Option

Before you start adding the expires headers in WordPress, it’s important to check whether your website runs on a Nginx or Apache server. Let’s discuss this first, then we’ll show you how to add expires headers WordPress feature.

To find this out, right-click anywhere on your website and choose Inspect.

Add Expires Headers In WordPress - Choose Inspect Mode

Go to Network, reload your web page, and click on your domain name directly under the Name column. Then, find Server under the Headers tab. Here, you’ll see which server your WordPress site is using. In our example, it’s LiteSpeed, an Apache alternative.

Add Expires Headers In WordPress - Find Web Server

Now that you’ve identified the server type your site is using, you can follow the appropriate guide to add expires headers WordPress option for your setup. Use the links below to jump directly to the method that suits your server configuration.

How to Add Expires Headers WordPress in Apache

If your website uses Apache or an Apache alternative web server, like LiteSpeed, you need to edit the .htaccess file. It’s a critical configuration file for websites running on an Apache server. It controls important settings like redirects, caching, and security.

Since it directly affects how your website operates, handle it carefully. Again, if you haven’t created your website’s backup yet, we recommend you do that first. Then, go through the following steps to edit the .htaccess file using the Hosted.com cPanel:

Login to your hosting account and open cPanel. Then, go to Files File Manager.

Add Expires Headers In WordPress - Access File Manager

Navigate to the public_html folder (or the root directory of your website). Then, look for the .htaccess file.

Add Expires Headers In WordPress - Locate .htaccess File

If you can’t find the .htaccess file in your WordPress directory, it may be hidden due to your File Manager’s settings, or it hasn’t been created yet. To check for hidden files, follow these steps: 

  1. Click Settings in the top-right corner of the File Manager.
  2. In the settings popup, enable Show Hidden Files (dotfiles) to show hidden files.
  3. Lastly, click Save, and the .htaccess file should appear. 
Add Expires Headers In WordPress - Show Hidden Files in File Manager

If the file is still not visible, it may not exist yet. In this case, you can create it manually within the File Manager to ensure proper functionality. Ensure you create the file in the public_html folder.

Add Expires Headers In WordPress - Create File Manually

Once you have the .htaccess file, right-click on it and choose Edit to open it in the editor.

Add Expires Headers In WordPress - Edit .htaccess File

Now, it’s time to add expires headers WordPress code. Here’s the code snippet to use:

## EXPIRES HEADER CACHING ##
<IfModule mod_expires.c>
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 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 image/x-icon "access 1 year"
ExpiresDefault "access 3 days"
</IfModule>
## EXPIRES HEADER CACHING ##

These settings suit most WordPress websites, but you can modify the periods to fit your requirements. The code assigns different cache expiration durations depending on the file type. For instance, images are cached for longer than HTML, CSS, JavaScript, and other files, as images tend to remain unchanged over time.

In the above code snippet, <IfModule mod_expires.c> ensures the server supports the expires headers before applying the rules. ExpiresActive On turns on the expires headers feature. ExpiresByType defines caching durations for specific file types, like images, CSS, and JavaScript. Then, ExpiresDefault sets a default caching time for files not listed.

After adding this code, save the .htaccess file and close it. This will immediately apply the new caching rules to your site.

Add Expires Headers In WordPress - Add Code in .htaccess File

Important: If the code is added incorrectly, it can break your WordPress website. Always double-check your edits and test the site after saving (we show you how to test it below).

How to Add Expires Headers WordPress in Nginx

If your WordPress blog or website is hosted on an Nginx server, you must modify the server configuration file to enable the expires headers. The process for accessing and editing this file can vary depending on your hosting provider. These files are usually located in one of the following directories:

/etc/nginx/nginx.conf

/etc/nginx/conf.d/

/usr/local/nginx/conf/

However, if you’re unsure how to access the configuration file and continue, contact your web hosting support team for assistance.

Once you access the configuration file, follow these steps to add expires headers WordPress code:

Open the Nginx configuration file using an editor of your choice. For instance, you can use nano editor in your terminal: 

sudo nano /etc/nginx/nginx.conf

Inside the server block, add the following code snippet:

location ~* \.(jpg|jpeg|png|gif|ico|svg|css|js|otf|ttf|woff|woff2)$ {
       expires 365d;
       add_header Cache-Control "public";
}

This code ensures that browsers cache specific file types for 365 days. Here’s what each part of the code does:

location ~* \.(...)$ 
<!-- targets specific file extensions like images, fonts, CSS, and JavaScript -->
expires 365d; 
<!-- line sets the cache expiry to 365 days. You can adjust this duration based on how often your files change. -->
add_header Cache-Control "public"; 
<!-- line adds a cache-control header, making these files publicly accessible for caching. -->

Once you’ve added the code, save your changes and restart the Nginx server to apply the new settings.

Verify Expires Headers Implementation

Once you’ve added the expires headers, check if they are working correctly. Testing ensures that your changes are active and your website is optimized for faster performance. Here’s how you can verify the implementation using simple tools and steps:

Use Online Tools

Online tools like GTmetrix make it easy to confirm whether expires headers are active on your site. These tools analyze your website’s performance and show caching details. Here’s how to use GTmetrix:

Open your browser and go to the GTmetrix website. If you have an account, sign in. Otherwise, sign up for free. Once logged in, enter your website URL (domain name) and click Analyze.

Add Expires Headers In WordPress - Test Website with GTmetrix

Wait a few seconds for the tool to finish checking your WordPress site. Once it’s done this, go to Waterfall in the report. Select any resource, such as an image or stylesheet, to view its details (in our example, we check for images).

Then, click your required link under the URL. Navigate to the Headers tab and locate expires field to see if the expires headers feature is implemented successfully.

Add Expires Headers In WordPress - Check Expires Headers Using GTmetrix

Use Browser Developer Tools

You can also use your browser’s built-in developer tools to check if the expires headers are active on your WordPress website. Here’s how:

First, open developer tools. In Chrome or Edge, press Ctrl + Shift + I (Windows) or Cmd + Option + I (Mac). Go to the Network tab. Ensure Disable cache is unchecked. Why?

Disable cache temporarily prevents the browser from using its cached files during testing. When this option is checked (enabled), the browser forces a fresh download of all files from the server every time the page loads.

This is useful for website debugging but does not show how caching works for regular visitors. To verify the expires headers in WordPress, you need to see how your website behaves with caching enabled, as it would for normal users. When Disable cache is unchecked, the browser uses cached files according to the expires headers you’ve set.

Next, refresh the page (press F5), and click on a file (e.g., an image or CSS file) under the Name column to view its headers. Then, look for expires under Headers. It should match the caching rules you set in your configuration file.

Add Expires Headers In WordPress - Verify Expires Headers
Strip Banner Text - Speed up your site with Hosted.com's optimized WordPress Hosting and tools. [Get started] title=

FAQS

Do expires headers work on all hosting providers?

Expires headers typically work on most hosting providers that support Apache or Nginx servers. However, if you’re using shared hosting or a managed WordPress host, you may need to check with your hosting provider to confirm if server-level changes, like editing .htaccess or Nginx files, are allowed.

If I add the expires headers WordPress feature, will it impact SEO?

Yes, adding expires headers in WordPress can positively impact SEO. Search engines prioritize fast-loading websites, and the expires headers help achieve that by enabling browser caching. Faster websites lead to lower bounce rates, better user engagement, and enhanced rankings in search results.

What happens if I set expires headers incorrectly?

If expires headers are not configured correctly, your site may show outdated files to visitors or fail to load properly. For example, setting very long expiration times for frequently changing files can cause issues. Always test your site after adding the expires headers to ensure everything works smoothly.

Is adding expires headers enough to optimize my website?

While expires headers greatly improve load times, they’re just one part of website optimization. Combine them with other techniques like Gzip compression, image optimization, and using a content delivery network (CDN) to maximize your site’s speed and performance.

Can expires headers cause issues with dynamic content?

Dynamic content, such as user-specific data or frequently updated pages, shouldn’t be cached for long periods. Set shorter expiration periods or exclude these files from caching entirely. This ensures visitors always see the most updated content.

How To Create A Membership Website In WordPress

How To Schedule A Post In WordPress: 2 Easy Methods

WordPress Excerpt Length: Definition & How To Change It

How to Update WordPress Plugins: A Step-by-Step Guide

How To Reduce HTTP Requests On WordPress Websites: 7 Easy Ways