How to retrieve a remote page using WordPress

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( '' );
if( is_wp_error( $response ) ) {
   echo 'Something went wrong!';
} else {
   echo 'Response:<pre>';
   print_r( $response );
   echo '</pre>';

If you enjoyed this article, please consider sharing it!

1 Comment

  1. Otto Bickes 9 years ago

    WONDERFUL Post.thanks for share..extra wait .. ?

Leave a reply

Your email address will not be published. Required fields are marked *