
Do you want to be able to get the content, as well as file info, of a remote file in order to use it on your WordPress install? Today’s recipe will let you know how you can do it easily.

Do you want to be able to get the content, as well as file info, of a remote file in order to use it on your WordPress install? Today’s recipe will let you know how you can do it easily.
Just use the wp_remote_get() function (Or wp_remote_post() is you prefer using the POST method) to retrieve the desired url. The example below shows how to retrieve an url and display its content as well as the file info.
This code can be used anywhere on your template files.
$response = wp_remote_get( 'http://foo.com/file.txt' );
if( is_wp_error( $response ) ) {
echo 'Something went wrong!';
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}
2 Responses
Can wp_remote_get also retrieve and display web page/s? Thanks.
I want to display .php page (output of it, not code) from remote site
Trackbacks: