What are some best practices for displaying specific data from an external website on a WordPress homepage using PHP?

When displaying specific data from an external website on a WordPress homepage using PHP, it is important to use the WordPress HTTP API to fetch the data securely. You can then parse the retrieved data and display it on your homepage using PHP.

// Make a GET request to the external website
$response = wp_remote_get( 'https://example.com/api/data', array( 'timeout' => 15 ) );

// Check if the request was successful
if ( is_wp_error( $response ) ) {
    echo 'Error fetching data';
} else {
    // Parse the JSON response
    $data = json_decode( wp_remote_retrieve_body( $response ), true );

    // Display the specific data on the homepage
    echo $data['specific_data'];
}