DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

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>';
}

Credits: WordPress Codex.

2 Comments

  1. Can wp_remote_get also retrieve and display web page/s? Thanks.

  2. I want to display .php page (output of it, not code) from remote site

Leave a Comment

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