HomeSEOHow to Improve HTTP...

How to Improve HTTP Response Header In WordPress

A text record information that a Web server transmits back to a client’s browser in response to receive an HTTP request. The HTTP response header includes file formate, size, and time that the server sends back to the client and data about the server itself. The header is attached to that file, returned to the client. In this article, we will discuss three 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 the header.php file.

header.php and function.php

 

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

<?php
unset($headers['Vary']);
header('Vary:Accept-Encoding', true);
?>
<!DOCTYPE html>
<html <?php language_attributes( 'html' ); ?>>
<head>

 

Note:- 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.

2. Function.php

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

Place the below code in the function.php

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

Note: – You can edit these files using an 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.

Check out: 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"
</IfModule>

.htaccess

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, 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.”

Most Popular

More Articles

Choosing The Right Images For Your Website Design

When you plan to create your own website, one of the...

Books Begone! How do People Read in 2022

It goes without saying that people consume literature in a completely...

How to Check if a Website is Legit or Trying to Scam You

Banking, shopping, and interacting with businesses have all become a lot...

5 Tips To Improve E-commerce SEO

One of the most critical aspects of an e-commerce site is...

Read Now

Top 6 Digital Marketing Strategies You Must Follow

One of the best digital marketing techniques is word of mouth. Every person has the same intention that if they get positive reviews about a particular service, then they tend to utilize it.In this case, as a digital marketer, you have to take care of your services...

How SEO Services Can Benefit Your Brand In 2023    

Do you want to gain the maximum benefit from SEO services? If yes, you have to follow certain tricks to help you meet your goals within a specific time. Proper schemes can make things work for you in the correct direction.Without appropriate SEO services, your company cannot...

How to calculate Ad Revenue & 7 ways to increase it

Estimating how much revenue a business makes can be tough but leveraging the right tools that accurately estimate publishers' ad earnings makes it a bit easier.Many variables influence your ad revenue, such as the layout of the site, the number of ads, visitor demographics, ad viewability, etc....