W3cubDocs

/WordPress

WP_HTTP_Requests_Response::header( string $key, string $value, bool $replace = true )

Sets a single HTTP header.

Parameters

$keystringrequired
Header name.
$valuestringrequired
Header value.
$replacebooloptional
Whether to replace an existing header of the same name.

Default:true

Source

public function header( $key, $value, $replace = true ) {
	if ( $replace ) {
		unset( $this->response->headers[ $key ] );
	}

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

Changelog

Version Description
4.6.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_http_requests_response/header