wp_remote_retrieve_body( array|WP_Error $response )

Retrieve only the body from the raw response.

Description Description

Parameters Parameters


(array|WP_Error) (Required) HTTP response.

Top ↑

Return Return

(string) The body of the response. Empty string if no body or incorrect parameter given.

Top ↑

Source Source

File: wp-includes/http.php

function wp_remote_retrieve_body( $response ) {
	if ( is_wp_error( $response ) || ! isset( $response['body'] ) ) {
		return '';

	return $response['body'];

Top ↑

Changelog Changelog

Version Description
2.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex


    Retrieving data from a JSON API:

    $url      = 'http://example.org/api';
    $response = wp_remote_get( esc_url_raw( $url ) );
    /* Will result in $api_response being an array of data,
    parsed from the JSON response of the API listed above */
    $api_response = json_decode( wp_remote_retrieve_body( $response ), true );

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