Support » Plugin: FancyBox for WordPress » [Plugin: FancyBox for WordPress] Autoplay youtube video in fancybox

  • I’m looking for the solution to autoplay videos with fancybox, after clicking on button(link) in a post.

    Everything works fine with none autoplay videos (using display none block). But when I’m adding &autoplay="1" parameter to Youtube url – in Google Chrome, video starts automatically, when the post is opened.

    I’ve created a shotcode for adding video button to post:

    function youtube_button_shortcode($atts) {
    		"text" => 'Video',
    		"id" => '1',
    		"button" => 'button-medium-red',
    		"url" => 'http://',
    		"autoplay" => '1',
    	), $atts));
    if (preg_match('%(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) {
    		$video_id = $match[1];
    '<a class="'.$button.' fancybox" target="_self" href="#video-button-'.$id.'">'.$text.'</span></a>
    <div id="video-button-'.$id.'" style="display: none;">
    <iframe src="'.$video_id.'?autoplay='.$autoplay.'&rel=0&showinfo=0" frameborder="0" width="810" height="450"></iframe>
    add_shortcode("youtube_button", "youtube_button_shortcode");

    shortcode example:
    [youtube_button text="Video" url="" id="1" button="button-medium-red"]

    I’ve found the solution to make video autoplay after clicking on button(link), but I had no luck on implementing it with this plugin.

    Could anybody help me with this. Will be much appreciated.

  • The topic ‘[Plugin: FancyBox for WordPress] Autoplay youtube video in fancybox’ is closed to new replies.