wp_remote_retrieve_header()
Retrieves the specified response header field from the passed response object.
Use wp_remote_retrieve_headers(), when you need to retrieve the entire array of response headers,
No Hooks.
Returns
Array|String. The value of the header field. An empty string if an incorrect parameter is provided or such a header field does not exist.
Usage
wp_remote_retrieve_header( $response, $header );
- $response(array) (required)
- The response object obtained using one of the functions: wp_remote_get(), wp_remote_post(), wp_remote_head() or wp_remote_request().
- $header(string) (required)
- The name of the header field whose value needs to be retrieved.
Examples
#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() wp remote retrieve header code WP 6.8.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 '';
}