Easy YouTube Gallery

Quick and easy make gallery for custom set of YouTube videos provided in shortcode, and autoplay video on click in Magnific PopUp lightbox.

FAQ

Features

  • Custom set of ID’s provided as shortcode attribute id (single of multiple ID’s separated by comma)
  • Custom additional class for targeted styling (if you need to blend gallery in your theme)
  • Custom number of columns to distribute thumbnails to (min 1, max 8)
  • Responsive thumbnails
  • Autoplay with Magnific PopUp lightbox
  • Well marked with classes

Classes

  • Main container:
    • .easy_youtube_gallery
    • .col-# for number of columns (default is 1, supported up to 8)
    • .ar-16_9 for 16:9, .ar-4_3 for 4:3 or .ar-square for 1:1 aspect ratio
    • custom class provided by shortcode attribute class
  • Anchor:
    • .eytg-item
    • .eytg-item-# for order number of item
    • .eytg-item-first for first item in gallery block
    • .eytg-item-mid for middle items in gallery block
    • .eytg-item-last for last item in gallery block
  • Thumbnail:
    • .eytg-thumbnail is class for span where we set video thumbnail as background image
  • Play icon
    • .eytg-thumbnail:before is pseudoclass for play icon

Download

ChangeLog you can find here. For download visit official WordPress.org page here http://wordpress.org/plugins/easy-youtube-gallery/ or get package below (latest or some of older versions if you like):

Installation

  1. Login to your WordPress.
  2. Go to Plugins -> Add New.
  3. Type to Search Plugins field keyword Easy YouTube Gallery and press Enter on your keyboard.
  4. Click Install Now button.
  5. When plugin is successfully installed, clik link Activate Plugin
  6. Insert shortcode [easy_youtube_gallery id=YT_VIDEO_ID,YT_VIDEO_ID,YT_VIDEO_ID...,YT_VIDEO_ID] (replace YT_VIDEO_ID with your set of YouTube video ID’s)

How to Use?

Please note! If you doing copy&paste from code above, before you paste content to page, post or text widget content, clear all formatting by paste&copy to/from Notepad or other plain text editor!

View Live Demo Here

Shortcode parameters

  • id (required) single YouTube video ID or multiple ID’s separated with comma
  • ar (optional) aspect ratio of thumbnails; default is ar-16_9 for 16:9, but also supported ar-4_3 for 4:3 and ar-square for 1:1
  • cols (optional) for number of columns to distribute thumbnails in; devault is 1, supported up to 8
  • thumbnail (optional) for YouTube size of thumbnail; default is hqdefault but we can use:
    • 0 have resolution 480x360px
    • 1, 2 and 3 have resolution 120x90px (first, second or third frame)
    • default have resolution 120x90px (Default Quality)
    • mqdefault have resolution 320x180px (Medium Quality)
    • hqdefault have resolution 480x360px (High Quality)
    • sddefault have resolution 640x480px (Standard Definition) and does not exists for lowres videos
    • maxresdefault have resolution 1920x1080px (Full HD) and does not exists for lowres videos
  • controls (optional) to optionally hide playback controls in lightbox player (default is 1 that means “display controls”, but you can set it to 0 to hide controls)
  • playsinline controls whether videos play inline or fullscreen in an HTML5 player on iOS. Learn more on Google Developers
  • privacy (optional) enables enhanced privacy which means that YouTube won’t store information about visitors on your web page unless they play the video.
  • class (optional) to add custom style class if you wish to target specific styling for your own needs

Preview

Easy YouTube Gallery preview
Easy YouTube Gallery preview

FAQ

Do I need to wrap shortcode parameters to doublequotes or singlequotes?

No. I even suggest to you avoid wrapping shortcode parameters to double/single quotes to prevent broken output when some plugins modify content with nasty filters.

Just avoid empty space between ID’s.

Support

If you need help, first try to read documentation and then check community support forum.

And we appreciate your support

Spread voice about Easy YouTube Gallery on social networks, rate and review on WordPress.org, feedback in comments below or

6 thoughts on “Easy YouTube Gallery”

  1. Hi I like your plugin of youtube gallery, I needed put code and add any lines of code for put title of video , inserted for user or show automatic of youtube.
    I like send us the new code and put my name in your credits.
    thanks folks!

    this is the code
    [easy_youtube_gallery id=JN-IDq0Nlhs,q1n2AQKbz8Q ar=16_9 cols=2 thumbnail=hqdefault controls=1 class=mySuperClass titles=Inside_house_tour,Aerial_video_of_the_house]

    in this the video titles dont put especial characters or blank spaces, put “_” for replace the blank spaces, and separated with comma

    this is the new code:

    ”, // Single or array of YouTube video ID’s
    ‘cols’ => 1, // Number of columns (1-8)
    ‘ar’ => ’16_9′, // empty for 16:9 or or 4_3 or square
    ‘thumbnail’ => ‘hqdefault’, // 0, 1, 2, 3, default, mqdefault, hqdefault, sddefault, maxresdefault
    ‘controls’ => 1, // Optionally hide player controls
    ‘class’ => ”, // Custom block class
    ‘titles’ => ”, //single or array of video title’s – andresvillegass
    ),
    $atts
    )
    );

    // Start output
    $output = ”;

    // Complain if we don’t have provided ID’s
    if ( empty($id) ) {
    return ‘Please provide ID`s for some YouTube videos’;
    }

    // Now enqueue plugin JS as we need it
    if ( ! wp_script_is( ‘easy-youtube-gallery’, ‘enqueued’ ) ) {
    wp_enqueue_script( ‘easy-youtube-gallery’ );
    }

    // Make array of video ID’s and prepare other var’s
    $ids = explode(‘,’, $id);
    $total_items = count($ids);
    $item_num = 0;

    //make array of video titles – andresvillegass
    $vec_titles = explode(‘,’,$titles);

    // Open gallery container
    $output .= “”;
    //init index in vec of titles
    $index_titles = 0; //index of control vec titles – andresvillegass
    // Process each video
    foreach ( $ids as $video_id ) {
    // Trim spaces from Video ID
    $video_id = trim($video_id);

    // Increase number of items and prepare position class
    ++$item_num;
    if ( $item_num == 1 ) {
    $item_position = ‘first’;
    } elseif ( $item_num == $total_items ) {
    $item_position = ‘last’;
    } else {
    $item_position = ‘mid’;
    }

    //obtain atts of video in youtube – andresvillegass
    $content_video = file_get_contents(“http://youtube.com/get_video_info?video_id={$video_id}”);
    parse_str($content_video, $ytarr);//Ex: obtain title of video $ytarr[‘title’];

    // Construct HTML structure for single item
    $output .= ““;
    $output .= ““;

    //valid if vec titles – andresvillegass
    if(isset($vec_titles[$index_titles]) && $vec_titles[$index_titles] !==””){
    $output .= ““.str_replace(“_”,” “,$vec_titles[$index_titles]).”“; //title write for the user – andresvillegass
    $index_titles++;
    }else{
    $output .= ““.str_replace(“_”,” “,$ytarr[‘title’]).”“; //title obtain of youtube – andresvillegass
    }

    $output .= ‘‘;

    } // END foreach ( $ids as $video_id )

    // Add clearfix after latest thumbnail
    $output .= ”;

    // Close gallery container
    $output .= ““;

    // Print out prepared HTML structure
    return $output;

    } // END public function shortcode($atts)

    /**
    * Register TinyMCE button for EYTG
    * @param array $plugins Unmodified set of plugins
    * @return array Set of TinyMCE plugins with EYTG addition
    */
    function mce_external_plugins($plugins) {

    $plugins[‘eytg’] = plugin_dir_url(__FILE__) . ‘inc/tinymce/plugin.min.js’;

    return $plugins;

    } // END function mce_external_plugins($plugins)

    /**
    * Append TinyMCE button for EYTG at the end of row 1
    * @param array $buttons Unmodified set of buttons
    * @return array Set of TinyMCE buttons with EYTG addition
    */
    function mce_buttons($buttons) {

    $buttons[] = ‘eytg_shortcode’;
    return $buttons;

    } // END function mce_buttons($buttons)

    } // END class WPAU_EASY_YOUTUBE_GALLERY

    // Initialise class
    new WPAU_EASY_YOUTUBE_GALLERY;

    } // END class_exists WPAU_EASY_YOUTUBE_GALLERY

    1. Hi Andres,

      Interesting idea. Solution is OK for couple videos, but if you wish to add a lot of items (5, 10, 20, 40), then getting details about video through get_video_info is slow, so YouTube Data API is better solution (to get details about all videos in single run). Also, displaying titles must be optional, then selecting location (above/below thumbnail), etc.

      Use call to youtube.videos.list and retrieve fields items(id,snippet(publishedAt,title,description)) for id of already provided array of YT videos, to get only what you need click here

      Thank you for your solution, I’ll consider new features during next month.

  2. I am not an expert coder so could you provide the facility for titles in the code for your next upgrade. Thanks a million.

Leave a Reply

Your email address will not be published. Required fields are marked *