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

---

# WP_REST_Request::set_headers( array $headers, bool $override = true )

## In this article

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

Sets headers on the request.

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

 `$headers`arrayrequired

Map of header name to value.

`$override`booloptional

If true, replace the request’s headers. Otherwise, merge with existing.

Default:`true`

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

    ```php
    public function set_headers( $headers, $override = true ) {
    	if ( true === $override ) {
    		$this->headers = array();
    	}

    	foreach ( $headers as $key => $value ) {
    		$this->set_header( $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#L295)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api/class-wp-rest-request.php#L295-L303)

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

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

Sets the header on request.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_request/set_headers/?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_headers%2F)
before being able to contribute a note or feedback.