Custom YouTube Hashtag and Channel Playlists

Design your own video strategy with custom playlists

At RebelMouse, we have the ability to implement almost any idea thanks to the power of our Layout & Design Tool. One use case is the ability to easily create custom YouTube playlists based on hashtags.

For example, if your company uses the #OurCompany hashtag, you could create a custom YouTube playlist on your website that pulls in content from that stream. You can also customize the playlist so that it only pulls in videos from a certain YouTube channel, or from a single channel without a hashtag:


The key to creating a custom playlist is to use YouTube's API to pull content. Let's explore how to pull content based on a hashtag, regardless of the channel.

Query for a Playlist Based on a Hashtag

The first step is to create a JavaScript variable for the query that will pull from the YouTube API. For example:

var queryStr = 'https://www.googleapis.com/youtube/v3/search?part=snippet&q=' + queryHash + '&type=video&videoCaption=any&videoDefinition=any&videoDimension=any&videoDuration=any&videoEmbeddable=any&videoLicense=any&videoSyndicated=any&videoType=any&key=' + key + '&maxResults='+maxResults;

For playlists based just on hashtags, there are three required parameters:

  • QueryHash: Your custom hashtag.
  • MaxResults: Fetch x videos, where x equals the maximum number of videos you want to pull. It can be any positive integer value.
  • Key: The API key. (This will be shared by the owner of the YouTube channel. See this guide that describes how to get an API key.)
  • ChannelId: This is an optional parameter. If it's provided in your query, it will only fetch videos from the channel ID you designate, otherwise it will fetch videos from any channel. Click here to learn how to locate a channel's ID.

Query for Playlists Based on Hashtags From a Single Channel

Here is the API query using the ChannelId parameter:

https://www.googleapis.com/youtube/v3/search?part=snippet&q=' + queryHash + '&type=video&videoCaption=any&videoDefinition=any&videoDimension=any&videoDuration=any&videoEmbeddable=any&videoLicense=any&videoSyndicated=any&videoType=any&key=' + key + '&maxResults=' + maxResults + '&channelId='+ channelId;

Understanding the JavaScript Logic

Now that we have an understanding of which query strings to use when making requests to the YouTube API, let's dive into how the JavaScript logic works

The basic idea is that we use the fetch API built into modern browsers to make Ajax requests to the YouTube API. Next, it fetches a response in JSON, and then we parse it and display the response in a video format using iframes.

Here is an example of a JSON response from the YouTube API:

{
 "kind": "youtube#searchListResponse",
 "etag": "\"Fznwjl6JEQdo1MGvHOGaz_YanRU/zdxYH_AS29xYgdx2YxQYxPeLj-I\"",
 "nextPageToken": "CAEQAA",
 "regionCode": "IN",
 "pageInfo": {
  "totalResults": 12,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": "\"Fznwjl6JEQdo1MGvHOGaz_YanRU/77ZWdQpKmM3r0vin9RorTTevnQc\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "iv0N7i2virY"
   },
   "snippet": {
    "publishedAt": "2019-07-04T08:40:09.000Z",
    "channelId": "UCJv753whZjpW22UfmaJbx4Q",
    "title": "From Kurils with Love: The Expedition Trailer",
    "description": "On Monday, the 8th July, an unusual expedition is setting sails in the town of Petropavlovsk in Kamchatka. A group of filmmakers, adventurers, climbers, ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/iv0N7i2virY/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/iv0N7i2virY/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/iv0N7i2virY/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Tomorrow Unlocked",
    "liveBroadcastContent": "none"
   }
  }
 ]
}

Sample Code

Below are some sample codes for using JavaScript to fetch a response for videos based on a hashtag and then render them as an iframe video player:

<div class="hash-videos"></div><button id="load-more-videos" class="load-more" onclick="LoadMore()">Load More</button><style>
.hash-videos {
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;
}
.yt-iframe {
margin: 0px 10px 0px 0px;
width: 340px;
padding: 5px;
}
/* tablets */
@media screen and (min-width: 768px) and (max-width: 1023px) {
 .yt-iframe {
  margin: 0 auto;
  width: 50%;
  box-sizing: border-box;
  }
}
  /* small devices */
@media screen and (max-width:767px) {
  .yt-iframe {
  margin: 0;
  width: 100%;
  padding: 0 0 15px 0;
  }
}
.load-more {
background: black;
border: 1px solid;
padding: 10px 20px;
width: 200px;
margin: 40px auto 50px;
display: block;
font-size: 15px;
}
</style><script>
  var queryHash = ""; //"fromkurilswithlove";
  var maxResults = 6;
  var key = "AIzaSyC5PqJgz18fIBjd9Yq3eA6cmL3EfmrbL1w";
  var pageToken = "";  // Pagination Logic.
  var channelId = "UCJv753whZjpW22UfmaJbx4Q"; // TomorrowUnlocked
  function LoadMore() {
 fetch('https://www.googleapis.com/youtube/v3/search?part=snippet&q=' + queryHash + '&type=video&videoCaption=any&videoDefinition=any&videoDimension=any&videoDuration=any&videoEmbeddable=any&videoLicense=any&videoSyndicated=any&videoType=any&channelId='+ channelId +'&key=' + key + '&maxResults='+maxResults+'&pageToken='+pageToken)
    .then(
      function(response) {
        if (response.status !== 200) {
          console.log('Looks like there was a problem. Status Code: ' +
            response.status);
          return;
        }
        // Examine the text in the response
        response.json().then(function(data) {
          renderVideos(data);
          console.log(data);
        });
      }
    )
    .catch(function(err) {
      console.log('Fetch Error :-S', err);
    });
  }
  function renderVideos(data) {
    console.log(data.items.length);
    var videosData = data.items;
    var playerFrame = document.getElementsByClassName("hash-videos")[0];
    console.log(playerFrame);    
    for(var i = 0; i < videosData.length; i++) {
        /*<div class='yt-iframe'><iframe title='' type='text/html' src='http://www.youtube.com/embed/id frameborder='0' allowFullScreen></iframe><div>*/
        var ytdiv = document.createElement("div");
        ytdiv.setAttribute("class","yt-iframe");
          var ytIframe = document.createElement("iframe");
          ytIframe.setAttribute("src", "https://www.youtube.com/embed/" + videosData[i].id.videoId);
        ytIframe.setAttribute("title", videosData[i].snippet.title);
        ytIframe.setAttribute("allowFullScreen", "true")
        ytIframe.setAttribute("frameborder", 0);
        ytIframe.setAttribute("width","340px");
        ytdiv.appendChild(ytIframe);
        playerFrame.appendChild(ytdiv);
    }
    //check if we have more videos else hide load more button
    if(data.nextPageToken) {
      pageToken = data.nextPageToken; //YT response gives a token for next page fetch.
    } else {
      pageToken = "";
      var x = document.getElementById("load-more-videos");
      x.style.display = "none";
    }
  }
  LoadMore();
</script>

If you have any questions or need help implementing this or any other feature — depending on the nature of the request, it may require services hours from us to complete the work — please email support@rebelmouse.com or talk to your account manager today.

Why RebelMouse Is the Best Content Marketing Platform

RebelMouse is a unique platform and company. The company was founded on the vision that media companies would need an always-modern solution to thrive in the new connected internet, and that brands would have to behave like new media companies and use the same platforms.

Keep reading... Show less

Why Premium Creative Agencies and CTOs Choose to Develop on RebelMouse vs. WordPress and Drupal

The Intersection of Design and Development: Where Your Clients Thrive

We started RebelMouse seven years ago knowing that there was a fundamental design flaw in the world of traditional CMSs: Every instance, on every platform, had to be updated independently. It's similar to an era when users had to manage their own Microsoft Exchange Server for email. The costs of managing, maintaining, and iterating on a CMS to keep it awesome and world class is typically a $10 million-a-year endeavor. But even then, these cost-prohibitive CMSs are still behind the times.

Keep reading... Show less

Native Multivariate Testing at Scale With RebelMouse

What Differentiates Our Approach

There are many popular tools that allow you to perform experiments and A/B tests on your users — primarily Google Chrome Experiments and Optimizely. But all of these solutions are JavaScript additions to your web page that sidestep the problem of old, outdated, and clumsy CMSs. These solutions work by calling on a third-party JavaScript library that rewrites a page after it's rendered. This approach adds extra page weight and creates strange user experiences due to having to wait for everything to load and be rewritten on the fly.

At RebelMouse, we've solved this in a very elegant way. At the core level of our platform, we can natively render different layouts and track the exact differences in performance when comparing a test to your other layouts.

Keep reading... Show less

Modern E-Commerce: Blur the Line Between Content and Design

Create Modular + Reusable Design Patterns on RebelMouse

Content saturation is an industry-wide problem, and the e-commerce space is no exception given that it's filled with big brands, small Etsy stores, and everyone in between all fighting for similar audiences. The best way to fight this symptom is to understand your audience and provide them with what they want.

Keep reading... Show less

Instagram-style E-commerce Features on RebelMouse

Revolutionizing e-commerce on RebelMouse

Whether you're a brand with a blog or a media company with a site, driving purchasing behavior and building an audience that uses your content to find things they love to buy is vital. We're very proud to have built out the same functionality that everyone is now used to on Instagram, with layovers on images that lead to products with attribution.

Keep reading... Show less

Building Premium Communities and User Journeys on RebelMouse

RebelMouse is much more than just a replacement for a traditional CMS. Our platform is a tremendous community-building experience. Today's social ecosystem has given us a seemingly limitless number of premium creators who understand how to create gorgeous and relevant content that drives the growth of their own audiences. These creators and influencers are either experts in certain topics, or heavily engaged in targeted content that drives their interests. They're not only consuming the content they're passionate about, but they're contributing to the conversation, too. The new role of the editor is not just to cover the most important topics and people around their expertise, but also to invite those preferred influencers into their community and get them to participate in creating premium content.

Keep reading... Show less

Dynamic Voting: Grow Traffic and Engagement Organically

Help your audience find its voice.

Creating quality content is no longer on marketers alone. We live in a universe of creators who are willing to not only consume content that resonates, but play a role in the creation, promotion, and conversations surrounding it.

Since the start of RebelMouse, we've been on a journey to create dynamic media that is easier for content creators to curate and amplify on social. It's why we've built an online engagement platform centered around the power of communities that thrive naturally in the digital ecosystem.

Keep reading... Show less

How to Monetize Your Website in Today’s Publishing Environment

In order to define distributive publishing, we have to ask the following question: If you have quality content, but nobody sees it, does it even exist? The answer is no, because your content needs to be supported in a way that lets it move seamlessly across all channels, especially site, search, and social. But let's take this question a step further: If you can't monetize your content to generate the support it needs, how do you create quality content in the first place?

Keep reading... Show less

Making Sense of PageSpeed Insights and Core Web Vitals

Page speed and Core Web Vitals are an important piece of the SEO puzzle. Having a quick load time and passing Core Web Vitals are important factors in Google's search ranking and results. But there are multiple ways of testing your speed and vitals, and it can get very confusing to try and understand the results since different measuring tools can result in different scores.

Keep reading... Show less

Reach New Revenue Heights With RebelMouse’s Boost Spot Placement

Authentic sponsored content piques user interest and yields high rewards

Monetization has to be multifaceted. Publishers must deliver a site experience that makes the user a top priority without sacrificing the ability to generate ad revenue. After all, readers are no longer going to put up with irritating ad experiences that slow down their consumption of content. And since publishers can't rely on a few viral moments to make ends meet, successful ad campaigns must feel genuine and produce consistent returns to be effective.

The need for smart, sticky monetization methods is nothing new, but publishers and marketers alike are starting to perfect the modern ad experience better than ever before. This success is due in part to the increased use of sponsored content.

Sponsored content is the creation of content for a brand by a publisher — whether it's an article, video, listicle, or any other dynamic media — that is paid for by the brand. But here's the key: Sponsored content, when done correctly, is a valuable content experience that retains the same voice and integrity of the brand that's sponsoring the placement. This seamless integration into the natural flow of content that the publisher normally creates makes it one of the most effective ways to build site revenue. In fact, 80% of readers believe authentic content is the main factor that will drive them to follow or engage with a brand.

Keep reading... Show less

RebelMouse Q2 2021 Platform Performance Updates

Q2 of 2021 was a big quarter for the open web. Google delayed their release of SEO ranking by CrUX report, and they changed their method for Lighthouse scoring drastically. Our team was a few steps ahead of these changes, and we were able to update our platform so sites in our network had little, if any, performance interruptions.

We invested over 1,592 hours into our platform in Q2 2021 alone, and all of the sites on our platform received the benefits of these updates. To break it down into large buckets, we invested in the following key areas:

  • 538 hours dedicated to new features
  • 725 hours dedicated to improving existing features
  • 329 hours dedicated to performance and infrastructure updates

Here are the major updates that we've added to the RebelMouse platform in Q2.

Keep reading... Show less

How to Use the Pagination Element

You can add pagination to section, tag, and archive pages using RebelMouse's Layout & Design Tool. This can be done through our Pagination element:

Using the Properties card, there are three options that you can configure on the Pagination element:

Keep reading... Show less
Subscribe to Our Newsletter