oprah-winfrey-video-shortcode

Embed Oprah.com Videos in WordPress with Shortcode

I’m no Oprah fan. Not all all. However, a reader contacted me last night asking if I could help her add Oprah videos to her WordPress website. This article is for her. Keep in mind that while Oprah’s network extends beyond Oprah.com , the shortcode on this page relates specifically to that site.

The shortcode will add the video embed code with correct dimensions (the site’s code defaults to 100%), and we’ll add a title and description with the option of importing and embedding just the featured video thumbnail image.

The Result

To embed the video from this page without a title or description, use [oprah v="http://www.oprah.com/oprahshow/Our-Favorite-Moments-with-The-Daily-Show-Host-Jon-Stewart-Video"]. The result:

To render a title and/or description, use the boolean attributes of title and description. For example, too display a title and description (in addition to the video, of course) for this video we’ll use [oprah v="http://www.oprah.com/oprahshow/Oprah-Loses-Her-Cool-While-Golfing-with-Clint-Eastwood-Video" title="1" description="1"]. The result:

Oprah Loses Her Cool While Golfing with Clint Eastwood - Video

Description: Oprah had never golfed a day in her life when she hit the links with Clint Eastwood in 2003. She was understandably nervous alongside the famed actor and his wife. (Original airdate: November 3, 2003) (Source: OPRAH, Created Apr 13, 2015)

You should alter the returned HTML at the bottom of the shortcode function to return your desired HTML.

Video Thumbnail

To show a video thumbnail, add the attribute of thumb="1" to your shortcode. While the title and description are both available it’s unlikely you’ll want this behaviour. By default the image will link back to the video URL; to disable this feature, use link="0".

The featured video image for this video would be displayed with the shortcode of [oprah v="http://www.oprah.com/own-super-soul-sunday/Why-Jimmy-Carter-Says-He-Couldnt-Be-President-Today-Video" thumb="1" import="1"]. The result:

Why Jimmy Carter Says He Couldn't Be President Today - Video

You may import the video’s featured imaged to your local WordPress installation rather than link to the remote copy. To do this, use import="1".

Featured Video Images Imported into Local WordPress Installation

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, although it’s expected you will alter the shortcode function to reflect your desired behaviour. This means that you will only ever require minimal (if any) attributes other than the video page URL to generate your video.

v

The v is the full video URL. You should alter other attributes in the function so that you’ll only ever need to reference the video.

w

The w is the width of the video container. Oprah returns a 100% value by default but this leaves black bars either side of the page if your post container is wide, and distorts the video if it’s narrow. For that reason, we scale the video to ensure it looks as it should. You should set the width in the shortcode function to a value that sits nicely in your own post container.

h

The height (or h) is automatically scaled based on the width. If our scaling doesn’t quite work for you, manually adjust it as required.

title

Should you choose to return the video title, use title="true" in your shortcode.

description

Should you choose to return the video description, use description="true" in your shortcode.

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 tull list of date formatting options are available in the PHP manual .

align

The align attribute refers to the alignment of the video container. It should normally be left as center.

captionalign

The captionalign attribute determines if the title and description text should be aligned to the left, center, or right of the margin. For larger amounts of text left is the cosmetic preference.

thumb

If you choose to include a video thumb rather than a video, use thumb="true"

link

By default we’ll link the thumbnail (if referenced) back to the original video URL. To silence this link, use link="0"

import

If you render a thumbnail onto your page (thumb="1") and you wish to import the thumbnail image locally, use import="1". It is false by default.

Considerations

  • We’ve refrained from using timthumb to scale imported or remote images although including it is easy and can be done by referencing some of our older articles. If you do use timthumb and don’t import locally you should add oprah.com to your allowed_sites array.
  • While the video data is essentially scraped from the Oprah video page, it is only done once. Relevant data is stored locally in your own WP database for future retrieval. If the format of the Oprah meta data changes in the future we’ll update the code as required.
  • The title and description area is fairly generic and can easily be altered by returning your own HTML code at the bottom of the function.

Download the Code

You may download the shortcode function here .

Shortt URL for this post:

Leave a Reply

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