/** * Create shortcode for videos to be embedded into posts * Usage: [get-yt-player id="LwuY1hKP9ug" autoplay="false"] */ function getYtPlayer_shortcode($atts) { extract(shortcode_atts(array("id" => null, "autoplay" => false), $atts)); ob_start(); ?> <div class="video-embed"> <?php getYtPlayer($id, null, $autoplay); ?> </div> <?php return ob_get_clean(); }
<div class="video-embed"> <?php $iframe_string = get_field('video_embed_code'); if (preg_match('/youtube/', $iframe_string)) { /* * Below are my past failed attempts at regex */ // /embed\/(\w+((\-+\w+)?)+)((\?(rel|list)=(\w+((\-+\w+)?)+))+)?"/ // /embed\/(\w+((\-+\w+)?)+)(\?rel=\d+?)?"/ // /embed\/(\w+((\-+\w+)?)+)(\"|\?)/ // /embed\/(\w+((\-+\w+)?)+)\"|\?/ // /embed\/(\w+([\-+\w+]?)+[\-\w+]?)\"|\?/ preg_match('/embed\\/([\\w+\\-+]+)[\\"\\?]/', $iframe_string, $match); $video_id = $match[1]; getYtPlayer($video_id, get_the_ID(), false); } else { echo get_field('video_embed_code'); } ?> </div> <?php } ?> <?php } else { ?> <div class="post-featured-image"> <?php the_post_thumbnail('full'); ?>