wp_remote_head()WP 2.7.0

Gets the HTTP response for a request. Uses the HEAD request method. Retrieves only headers, without the response body.

This is a wrapper for using curl.

No Hooks.

Returns

Array|WP_Error.

  • array — The result is returned as an array and contains the HTTP headers, but does not retrieve the page data itself, i.e. the content (body) of the response to the request is not fetched, only the headers are obtained...

  • WP_Error is returned in case of a failed request.

Usage

wp_remote_head( $url, $args );
$url(string) (required)
URL of the request.
$args(array)
Request arguments. See the list of arguments in the description of wp_remote_request()
Default: array()

Examples

0

#1 Get the HTTP API response headers

$response = wp_remote_head( 'https://api.github.com/users/erusev' );
print_r( $response );

/* will output:
Array
(
	[headers] => Array
		(
			[server] => GitHub.com
			[date] => Thu, 10 Dec 2015 10:53:23 GMT
			[content-type] => application/json; charset=utf-8
			[connection] => close
			[status] => 200 OK
			[x-ratelimit-limit] => 60
			[x-ratelimit-remaining] => 54
			[x-ratelimit-reset] => 1449746444
			[cache-control] => public, max-age=60, s-maxage=60
			[last-modified] => Mon, 23 Nov 2015 13:19:37 GMT
			[etag] => W/"c8dad0c81351ce6451a9b7de7f7f0d8b"
			[vary] => Array
				(
					[0] => Accept
					[1] => Accept-Encoding
				)

			[x-github-media-type] => github.v3
			[x-xss-protection] => 1; mode=block
			[x-frame-options] => deny
			[content-security-policy] => default-src 'none'
			[access-control-allow-credentials] => true
			[access-control-expose-headers] => ETag, Link, X-GitHub-OTP, X-RateLimit-Limit
			[access-control-allow-origin] => *
			[strict-transport-security] => max-age=31536000; includeSubdomains; preload
			[x-content-type-options] => nosniff
			[x-served-by] => 139317cebd6caf9cd03889139437f00b
			[content-encoding] => gzip
			[x-github-request-id] => 05659C50:A398:252770C:566959A3
		)

	[body] => (always empty)
	[response] => Array
		(
			[code] => 200
			[message] => OK
		)

	[cookies] => Array
		(
		)

	[filename] => 
)
*/

Notes

Changelog

Since 2.7.0 Introduced.

wp_remote_head() code WP 7.0

function wp_remote_head( $url, $args = array() ) {
	$http = _wp_http_get_object();
	return $http->head( $url, $args );
}