Add Custom HTTP Headers Using a WordPress Plugin

,

HTTP headers are the name-value pairs that appear in an HTTP request and response message’s headers.

Custom HTTP headers are commonly used for various purposes, such as limiting bandwidth on your origin server, restricting CDN traffic, and adding custom functionality.

Maybe you want to add an x-hacker message with a link to your jobs page to recruit developers.

In this example, we’ll be adding a custom x-hacker to display a message.

  1. Install, Activate & Setup the Redirection plugin
  2. Open the plugin settings via wp-admin > Tools > Redirection
  3. Locate the Site tab
  4. Locate HTTP Headers and click Add Headers
  5. To add the x-hacker header choose Custom Header

We should now have something that looks like this. Update to save.

To check if your headers are working, you can run this in your computer’s terminal:

$ curl -I https://{YOUR DOMAIN NAME HERE}

The above cURL command should reflect something that looks like this:

ork@Ashleys-MacBook-Pro-2 ~ % curl -I https://ash1eygrace.com
HTTP/2 200 
server: nginx
date: Wed, 10 Nov 2021 16:22:18 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
link: <https://ash1eygrace.com/wp-json/>; rel="https://api.w.org/"
link: <https://ash1eygrace.com/wp-json/wp/v2/pages/27>; rel="alternate"; type="application/json"
link: <https://ash1eygrace.com/>; rel=shortlink
x-httpd-modphp: 1
host-header: 8441280b0c35cbc1147f8ba998a563a7
x-proxy-cache-info: DT:1

If you’re not seeing your custom header, depending on your host you might need to use this cURL command:

$ curl -I https://{YOUR DOMAIN HERE}/wp-json

Optionally, you can also check HTTP headers with Chrome.


Leave a Reply

Your email address will not be published. Required fields are marked *