Wednesday, May 27, 2020
Home Dynamic Skills How to Improve HTTP Response Header In WordPress

How to Improve HTTP Response Header In WordPress

A Complete How to

A text record information which a Web server transmits back to a client’s browser in response, to receive an HTTP request. The response header includes file formate, size, and time period that the server is sending back to the client and data about the server itself. The header is attached with that file, returned to the client. This article, we will discuss two methods.

Modify Http Response Header In WP Theme Source Code (header.php, function.php)

  1. Header.php

Install any WordPress theme editor if you don’t have a built-in function in your active theme.

  • Click on Appearance — Theme  Editor menu and select your WordPress Active theme.
  • Select your WordPress website active Theme and select header.php file.

header.php and function.php


Add below code at the beginning of header.php file before <!DOCTYPE html>. This code makes use of the PHP header function create or set related header values.

header('Vary:Accept-Encoding', true);
<!DOCTYPE html>
<html <?php language_attributes( 'html' ); ?>>


Note:- Some lines in source code already exists. In that case, you have to copy extra lines from the given code to avoid duplications and conflicts.

2. Function.php

Find the function.php (the method is same as you installed them editor and located header.php)

Place the below source code in the function.ph

function replace_wp_headers($headers) {
  $headers['Vary'] = 'Accept-Encoding';
  return $headers;
add_filter('wp_headers', replace_wp_headers);

Note: – You can edit these files by using FTP client like Filezilla or through cPanel file manager. Some lines in source code already exist. In that case, you have to copy extra lines from the given code to avoid duplications and conflicts. you have to go to your website’s root directory > wp-content > themes > your active theme.

How to Stop DDoS Attacks on your WordPress website

3 .htaccess file

This method is not at all times functional because plugins can modify headers value PHP source code. Anyways if you want to use this method in any case. just copy the below code in your .htaccess file and save.

<IfModule mod_headers.c>
   Header unset Vary
   Header set Vary "Accept-Encoding"


Note:- .htaccess file is located in the website’s root directory which can be accessed by using FTP client or cPanel. Always check your website’s functionality after adding any source codes. in any case, you find your website is not responding, just remove the code and save the file. This is just because in some cases the source codes don’t work because of any active plugin or “maybe you added the code which is missing any syntax”.

Thanks For Reading.

Most Popular

Types of Renewable Energy Sources, resources, advantages, and disadvantages

The basic concept of renewable energy. Classify different sources of renewable energy with descriptions and strengths and limitations. Describe the potential of solar energy...

Latest Technology Trends during COVID-19 pandemic

The World in 2020 has seen the COVID-19 pandemic as well as our massive dependency on digital technology. We have seen a phase shift of...

What is Artificial Intelligence (AI)? History and Why it is so Important

Artificial intelligence (AI) machines can learn from practice, familiarize with new efforts, and do human-like tasks. Most AI cases you hear today – from...

What is Blockchain technology? Everything you need to know

If you've been following banking, investing, or cryptocurrency for the past ten years, you may know "blockchain," the record-keeping technology behind the bitcoin network....

Recent Comments