wp_get_http_headers()
Retrieve HTTP Headers from URL.
No Hooks.
Return
\WpOrg\Requests\Utility\CaseInsensitiveDictionary|false
. Headers on success, false on failure.
Usage
wp_get_http_headers( $url, $deprecated );
- $url(string) (required)
- URL to retrieve HTTP headers from.
- $deprecated(true|false)
- Not Used.
Default: false
Examples
#1 Get HTTP headers by URL
Sometimes it is enough to get HTTP headers instead of getting all the content of the specified URL. Getting a server response is usually 2-3 times faster:
$r = wp_get_http_headers( 'http://wordpress.org' ); print_r( $r );
this code will display such an array:
Array ( [server] => nginx [date] => Sun, 02 Nov 2014 20:39:35 GMT [content-type] => text/html [content-length] => 154 [connection] => close [location] => https://wordpress.org/ )
#2 Processing GET request
We can send a GET request by receiving headers only and it will be processed by remote server. For example, we need to trigger the following URL to run some task: http://example.com?foo=param
:
wp_get_http_headers( 'http://example.com?foo=param' );
Changelog
Since 1.5.1 | Introduced. |
wp_get_http_headers() wp get http headers code WP 6.7.1
function wp_get_http_headers( $url, $deprecated = false ) { if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '2.7.0' ); } $response = wp_safe_remote_head( $url ); if ( is_wp_error( $response ) ) { return false; } return wp_remote_retrieve_headers( $response ); }