wp_remote_retrieve_header() WordPress Function

The wp_remote_retrieve_header() function is used to get the value of an HTTP header from the response returned by an HTTP request.

wp_remote_retrieve_header( array|WP_Error $response, string $header ) #

Retrieve a single header by name from the raw response.


Parameters

$response

(array|WP_Error)(Required)HTTP response.

$header

(string)(Required)Header name to retrieve value from.


Top ↑

Return

(array|string) The header(s) value(s). Array if multiple headers with the same name are retrieved. Empty string if incorrect parameter given, or if the header doesn't exist.


Top ↑

Source

File: wp-includes/http.php

function wp_remote_retrieve_header( $response, $header ) {
	if ( is_wp_error( $response ) || ! isset( $response['headers'] ) ) {
		return '';
	}

	if ( isset( $response['headers'][ $header ] ) ) {
		return $response['headers'][ $header ];
	}

	return '';
}


Top ↑

Changelog

Changelog
VersionDescription
2.7.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.