Related YouTube Videos

By Zenation | Version 1.0.2 | License: GPLv2

relatedYouTubeVideos is a free WordPress plugin that embeds a number of, well, YouTube videos that are related to your content. The list is put together by using the YouTube search API. And you can specify the relation between the videos and your content by:

  1. the title of your current post, page or custom post type.
  2. the tags of your current post, page or custom post type.
  3. any keywords you specify.

Also, this plugin offers you two ways to embed related videos:

  1. by using the shortcode [relatedYouTubeVideos] somewhere in your post/page content
  2. by using the WordPress widget "Related YouTube Videos" in any of your widget areas (multiple instances are possible)

The Shortcode

You can put the shortcode [relatedYouTubeVideos] anywhere you want inside the content of a page, post, or custom post type - as long as your WordPress theme is supporting shortcodes.

You can also add a number of attributes to configure the assembling of the list of videos that will be embedded:

I recommend always using the attributes 'relation', 'max', and if the relation shall be 'keywords' the 'terms' attribute. Depending on your design you might also set a custom width and height for the videos so they fit in properly.

Shortcode Example 1: [relatedYouTubeVideos relation="postTags" max="3"] Will show three videos coming back from the search YouTube for (all!) the tags you have assigned to this post or page.

Shortcode Example 2: [relatedYouTubeVideos relation="keywords" terms="monty python" max="5"] Will show five Monty Python videos from YouTube.

Shortcode Example 3: [relatedYouTubeVideos relation="postTitle" max="1" orderBy="viewCount" start="1"] Will show the second most popular video (the first being skipped) relating to your post or page title.

The Widget

The widget almost works the same way. Or at least it has the same options for configuring the video request. If you log into your WordPress backend and go to the "Appearance > Widget" menu (given that your theme supports widgets) you can drag&drop a widget instance into the widget area of your choice.

The *relatedYouTubeVideos* widget allows multiple instances. So you can put as many widgets as you like into as many widget areas as you like.

The difference between the widget and the shortcode is not in terms of functionality but usually in the context they reside. Widgets usually go into sidebars or footers and alike and the same widget usually shows up for many, if not all pages, just the same. Shortcodes are placed inside the actual content and therefore will only show up when the page or post where they're put is shown.

Errors

The videos will be embedded from YouTube by using its search API. This API call is being done by sending an internal request over the web. And as we all know, there can be a million reasons why even a service like YouTube cannot be reached all the time. If that's the case or a request itself is invalid for some reason you will get an error message and no videos! But instead of breaking your design by showing your visitors error messages, they will just see nothing: The error message will be hidden in the HTML source code in form of an HTML comment.

So if you don't see any videos while you think you should, please take a look at the HTML source code of your current page and look for "[relatedYouTubeVideos] Error...".