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.

Examples

0

#1 Get the last modified date of remote file from response header

$response = wp_remote_get( 'http://wp-kama.ru/wp-content/themes/wp-kama/style.min.css' );
$last_modified = wp_remote_retrieve_header( $response, 'last-modified' );

echo $last_modified; //> Fri, 17 Jun 2016 23:00:35 GMT

Changelog

Since 2.7.0 Introduced.

wp_remote_retrieve_header() code WP 6.4.3

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