15th Feb '24
/
9 comments

YouTube Playlist Bricks Query Loop

YouTube Playlist Bricks Query Loop

Updated on 16 Feb 2024

In the BricksLabs Facebook group a user asked:

I've been battling to display a YouTube Playlist in grid form on a site. The Bricks Video element does not allow for playlists.

From searching Bricks community platforms, most suggestions are to use a 3rd party plugin.

Is it at all possible to do this without a 3rd party plugin? If so; - I'd love to see a tutorial on this.

This Pro tutorial provides the steps to register a custom query type, which, when selected, enables you to use Bricks elements like Video, Heading, and Image to output the embedded video iframe, title, and thumbnail of videos of a specified YouTube playlist in a Bricks query loop.

We shall use YouTube Data API.

Step 1

Go to the Google Cloud Platform Console and get an API key for the YouTube Data API.

The general outline is that you’d first create a Project, switch to it, go to "APIs and services", click "Enable APIs and Services" button, search for youtube, click "YouTube Data API", enable it, go to Credentials, create a credential of API key type to get the API key.

Details:

  1. You need a Google Account to access the Google API Console, request an API key, and register your application.
  2. Create a project in the Google Developers Console and obtain authorization credentials so your application can submit API requests.
  3. After creating your project, make sure the YouTube Data API is one of the services that your application is registered to use:
    1. Go to the API Console and select the project that you just registered.
    2. Visit the Enabled APIs page. In the list of APIs, make sure the status is ON for the YouTube Data API v3.

Step 2

Keep your desired YT playlist's ID handy.

In this example, we shall use this playlist:

https://www.youtube.com/playlist?list=PL3VM-unCzF8ipG50KDjnzhugceoSG3RTC

so the ID is: PL3VM-unCzF8ipG50KDjnzhugceoSG3RTC

Step 3

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Introduction to Fetching API in Bricks

Introduction to Fetching API in Bricks

In this tutorial, we'll create a dynamic Chuck Norris quote picked from a public API to understand the basics of API fetching in Bricks. Create…
Categories:
Tags:
Using WP Grid Builder Facets with Bricks’ Query Loop

Using WP Grid Builder Facets with Bricks’ Query Loop

Update: This tutorial was written before WPGB had a Bricks add-on. Now, it is advisable to use that add-on instead. Get it from here. Updated…
Categories:
Pro
Parent Query Loop Object – Traversing Nested Query Loops Up in Bricks

Parent Query Loop Object – Traversing Nested Query Loops Up in Bricks

Bricks enables us to build nested query levels of unlimited levels. Here are a couple of examples: Sometimes, you might want to obtain the parent…
Categories:
Pro
6 Random Featured Posts in Alphabetical Order in Bricks

6 Random Featured Posts in Alphabetical Order in Bricks

How to output x number of random posts with a specific meta value set, in Alphabetical order.
Categories:
Pro
Posts Grouped by Month and Year in Bricks

Posts Grouped by Month and Year in Bricks

Nesting query loops with months & years in descending order, with the inner loop outputting the posts.
Categories:
Pro
How to Insert Element(s) Between Query Loop Posts in Bricks

How to Insert Element(s) Between Query Loop Posts in Bricks

Update on 16 Aug 2023: Follow this tutorial instead. This Pro tutorial shows how we can insert a Div (or any custom HTML) after nth…
Pro
ACF User Field Bricks PHP Query

ACF User Field Bricks PHP Query

In the Bricks Facebook group a user asks: my end goal was to create a set of cards that would display the Users that are…
Categories: