FancyBox for WordPress
Autoplay youtube video in fancybox (1 post)

  1. ndrwld
    Posted 4 years ago #

    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="http://www.youtube-nocookie.com/embed/'.$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="http://www.youtube.com/watch?v=XpOH2lWFEl8" 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.


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • FancyBox for WordPress
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic