-
I’m embedding those video’s with the shortcode and youtube url, but some url’s where not valid (anymore). I’ve build a check before I use your shortcode. It should be nice if this is implemented in your shortcode.
function yt_exists($videoID) { $theURL = "https://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=$videoID&format=json"; $curl = curl_init($theURL); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $body = curl_exec($curl); curl_close($curl); $result = json_decode($body, true); if ($result['title']){ return true; } else { return false; } } if (!get_field('youtube_url')) { continue;} $url = get_field('youtube_url'); parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars ); if ($my_array_of_vars['v']){ $youtubeid = $my_array_of_vars['v']; } else { $youtubeid = str_replace("https://youtu.be/","",$url); } if ($youtubeid){ if (!yt_exists($youtubeid)) { echo do_shortcode('[fvplayer src="'.get_field('youtube_url').'" lightbox="true;250;150" caption="'.get_the_title().'"]');} }