Code Snippet –

<?php
$imageSrcDefault = 'https://vikkidavisfitness.com/wp-content/uploads/2021/02/back2.jpg';
$id = get_field('video_id', get_the_ID());
$id = str_replace('https://vimeo.com/', '', $id);
if ($id != '') {
    if (get_field('vimeo_video_image', get_the_ID()) == '') {
        $args = [
            'headers' => [
                'referer' => 'https://vikkidavisfitness.com'
            ]
        ];
        $response = wp_remote_get("https://vimeo.com/api/oembed.json?url=https://vimeo.com/$id", $args);
        if (is_array($response) && !is_wp_error($response)) {
            $body = json_decode($response['body']);
            $imageSrc = $body->thumbnail_url;
            update_field('vimeo_video_image', $imageSrc, get_the_ID());
        }
    }
    if (get_field('vimeo_video_image', get_the_ID()) != '') {
        $imageSrc = get_field('vimeo_video_image', get_the_ID());
    } else if (get_field('poster_image', get_the_ID())!= '') {
        $imageSrc = get_field('poster_image', get_the_ID());
    } else {
        $imageSrc = $imageSrcDefault;
    }
} else {
    $imageSrc = $imageSrcDefault;
}
?>
»