If there's no cached version, let's get a joke $jsonurl = "http://api.icndb.com/jokes/random?limitTo=[nerdy]"; $json = wp_remote_get( $jsonurl ); if ( is_wp_error( $json ) ) { return "Chuck Norris accidentally kicked the server, it will be up soon!"; } else { // If everything's okay, parse the body and json_decode it $json_output = json_decode( wp_remote_retrieve_body( $json )); $joke = $json_output->value->joke; // Store the result in a transient, expires after 1 day // Also store it as the last successful using update_option if ($json_output->type = "success") { set_transient( 'chuck_norris', $joke, 60 * 1 ); } } } echo esc_html($joke); echo '<p><strong>Refresh Page for another great Chuck Norris Joke</strong></p>';