WP_HTTP_Response::header() WordPress Method

The WP_HTTP_Response::header() method is used to send a raw HTTP header to the client. This is useful for sending custom headers, such as cache control headers or Access-Control-Allow-Origin headers.

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

Sets a single HTTP header.


Parameters

$key

(string)(Required)Header name.

$value

(string)(Required)Header value.

$replace

(bool)(Optional) Whether to replace an existing header of the same name.

Default value: true


Top ↑

Source

File: wp-includes/class-wp-http-response.php

	public function header( $key, $value, $replace = true ) {
		if ( $replace || ! isset( $this->headers[ $key ] ) ) {
			$this->headers[ $key ] = $value;
		} else {
			$this->headers[ $key ] .= ', ' . $value;
		}
	}

Top ↑

Changelog

Changelog
VersionDescription
4.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.