Embed Varity.com Videos in WordPress with Shortcode

Variety is a weekly American entertainment trade magazine owned by Penske Media Corporation. Founcded in 1905 as a weekly rag, it’s since evolved into a websites-only service (since March 2013) covering the motion-picture industry and general entertainment news. The website features reviews, box office results, entertainment news, and a range of other entertainment services and features. More importantly, they provide a vast video library – the focus of today’s article.

The default video embed feature offered by Variety is actually quite crappy. When we looked at the default embed code we found a number of errors, not the least of which was the incorrect video container embed dimensions. The website uses the excellent JW player… but their techie guys just need to get their defecation together to solidify the experience for those that choose to use the default features.

Variety's crappy embed code.

In spite of the large number of errors, the array of high-quality videos they continue to publish can’t be ignored. If you’re like us and have a few entertainment-style websites, the code to correctly embed the video with an optional title and description will invariably come in handy.

Our shortcode function – not unlike the code we’ve provided in past weeks – will give you the option of embedding a featured image (thumbail) rather than the video. The video featured image will (optionally) be imported into your own WordPress image directory by default.

We scrape the Variety video page (only once) to retrieve details and then store the information in your WP database for future retrieval. While not the best means of achieving our end, it’s an accepted method, and somewhat necessary given the erroneous data the website currently returns.

Note: You should only include this function for Variety hosted media. If they show a YouTube video, use our shortcode to embed YouTube videos.

The Result

To embed a single video in your WordPress post or page, use the shortcode of [variety v="http://variety.com/video/the-muppets-kermit-comes-clean-about-miss-piggy-break-up/"] to return the following:

To include a title and description (either one or both can be returned by referencing the parameters below) we use the shortcode of [variety v="http://variety.com/video/everest-cinematographer-on-recreating-the-grueling-mountain-experience/" title="true" description="true"]. The result:

'Everest' Cinematographer on Recreating the Grueling Mountain Experience

Description: Cinematographer Salvatore Totino has filmed under rugged conditions before, but he told Variety’s David Cohen that shooting "Everest" was an different kind of adventure — but a rewarding one. (Source: Variety, Published Sep 22, 2015)

It seems that Variety’s video hosting is in a period of transition; if you encounter errors please let us know so we can quickly correct them.

Video Thumbnail

To include a video featured image, use [variety v="http://variety.com/video/the-muppets-kermit-comes-clean-about-miss-piggy-break-up/" thumb="1"]. It will return the following:

'The Muppets': Kermit Comes Clean About Miss Piggy Break Up

While the title and description attributes are available for the thumbnail image it’s unlikely you will want to use them.

The Shortcode Function

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

Shortcode Attributes

The following shortcode attributes are available that will modify the output of the video. Modifying the code every time you want to include a video is a nuisance, so alter the actual code to reflect your preferred default behaviour.

v

The v is the full video URL (as demonstrated in our examples). You should check that the video is hosted by Varity (and not YouTube) before including it.

w

You should set the w (width) to fit your own post container. By default it’s 540 pixels… but this may be too wide for a lot of WP themes.

h

The height (h) of the video is automatically determined so you don’t have to define it. Sometimes, however, the formatting we apply may not work for you and you’ll have to correct it yourself.

title

To include the title with the video, use title="1" or, for more permanent results, adjust your shortcode function. Defaults to false.

description

To include the video description with the video, use description="1" in your shortcode. For more permanent results adjust your shortcode function. Defaults to false. The decription includes a link back to the video and an original publication date (formatted as detailed below).

align

align determines the alignment of your video container. Best to leave it as center.

captionalign

The description looks a little ordinary when it centers over multiple lines. For that reason, you can choose to align text to the left with captionalign="left". Defaults to left.

date

The video description includes a creation date for the video. The date will inherit the formatting based on the value in your shortcode function. A full list of date formatting options are available in the PHP manual .

thumb

If you would prefer to return a video thumbnail image rather than the video, use thumb="true".

import

By default we’ll import the thumbnail image for every video you include on your website; it makes it easy to use it elsewhere or as a featured image. To cease importing, use import="0" or alter the shortcode function for default behaviour.

Variety images imported into your local WP library.

If you don’t import the image to your own WordPress installation we’ll reference the remote image instead.

link

The thumbnail image, if returned, will link to the video page by default. To silence this, use link="0". Defaults to true.

Download the Code

Download the shortcode function here .

Shortt URL for this post:

Leave a Reply

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