Title: WP_REST_Request::set_header
Published: December 9, 2015
Last modified: August 20, 2026

---

# WP_REST_Request::set_header( string $key, string $value )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_request/set_header/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_request/set_header/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_request/set_header/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_request/set_header/?output_format=md#changelog)

Sets the header on request.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_request/set_header/?output_format=md#parameters)󠁿

 `$key`stringrequired

Header name.

`$value`stringrequired

Header value, or list of values.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_request/set_header/?output_format=md#source)󠁿

    ```php
    public function set_header( $key, $value ) {
    	$key   = $this->canonicalize_header_name( $key );
    	$value = (array) $value;

    	$this->headers[ $key ] = $value;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/class-wp-rest-request.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/rest-api/class-wp-rest-request.php#L249)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api/class-wp-rest-request.php#L249-L254)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_request/set_header/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_REST_Request::canonicalize_header_name()](https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/)`wp-includes/rest-api/class-wp-rest-request.php` |

Canonicalizes the header name.

  |

| Used by | Description | 
| [WP_REST_Request::set_headers()](https://developer.wordpress.org/reference/classes/wp_rest_request/set_headers/)`wp-includes/rest-api/class-wp-rest-request.php` |

Sets headers on the request.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_request/set_header/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_request%2Fset_header%2F)
before being able to contribute a note or feedback.