wp_remote_retrieve_header()WP 2.7.0

Retrieve a single header by name from the raw response.

No Hooks.

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.

Usage

wp_remote_retrieve_header( $response, $header );
$response(array|WP_Error) (required)
HTTP response.
$header(string) (required)
Header name to retrieve value from.

Changelog

Since 2.7.0 Introduced.

Code of wp_remote_retrieve_header() WP 6.0

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 '';
}