wp_remote_retrieve_headers( array|WP_Error $response )

Retrieve only the headers from the raw response.


Description Description

See also See also


Top ↑

Parameters Parameters

$response

(array|WP_Error) (Required) HTTP response.


Top ↑

Return Return

(array|Requests_Utility_CaseInsensitiveDictionary) The headers of the response. Empty array if incorrect parameter given.


Top ↑

Source Source

File: wp-includes/http.php

function wp_remote_retrieve_headers( $response ) {
	if ( is_wp_error( $response ) || ! isset( $response['headers'] ) ) {
		return array();
	}

	return $response['headers'];
}

Top ↑

Changelog Changelog

Changelog
Version Description
4.6.0 Return value changed from an array to an Requests_Utility_CaseInsensitiveDictionary instance.
2.7.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by vee

    The returned value of wp_remote_retrieve_headers($response) will be something like this…

    Requests_Utility_CaseInsensitiveDictionary::__set_state(array(
       'data' => 
      array (
        'server' => 'nginx/1.10.3 (Ubuntu)',
        'date' => 'Wed, 09 Jan 2019 07:25:38 GMT',
        'content-type' => 'application/octet-stream',
        'content-length' => '1438086',
        'last-modified' => 'Tue, 01 May 2018 04:56:08 GMT',
        'etag' => '"5ae7f368-15f186"',
        'accept-ranges' => 'bytes',
      ),
    ))

    To access only one value:

    $headerResult = wp_remote_retrieve_headers($response);
    $headerResult['content-length'];

    You can just type in the array key.

    To get the whole array:

    $headerResult = wp_remote_retrieve_headers($response);
    $headerResultForPrint = (array)$headerResult;
    print_r($headerResultForPrint);

    You have to use type cast (array).

You must log in before being able to contribute a note or feedback.