WP Json lists posts from an external website

Use the following code to lists posts on an external website.
WP-JSON / API must be open on a WordPress website for this to work.

<?php

$response = wp_remote_get(

add_query_arg(
 array('per_page' => 4), // post limit
 'https://yoursite.com/wp-json/wp/v2/posts') //JSON Post feed
);

if( !is_wp_error( $response ) && $response['response']['code'] == 200 ) {
   $remote_posts = json_decode( $response['body'] ); // our posts are here
?>

  <ul class="blog-list">

  <?php foreach( $remote_posts as $remote_post ) { ?>

    <li>

        <h5><a href="<?php echo $remote_post->link; ?>" target="_blank"><?php echo $remote_post->title->rendered; ?></a></h5>

        <div class="time">

          <?php echo date("jS F, Y",strtotime($remote_post->date)); ?>

        </div>

    </li>

  <?php } ?>

  </ul>

<?php } ?>