RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Embed Wistia Videos In WordPress With Shortcode

Embed Wistia Videos In WordPress With Shortcode

Wistia is a video platform designed primarily for businesses. Unlike other video hosting services, it has an extremely powerful API that permits access to an array of analytics that gives you insight into how your video is watched and who watches it. We have only just started using it and - as is the case with all embed code that we'll ever use - we wanted a quick and easy shortcode to embed the videos without using the lengthy embed code that Wistia provides. This article will show you how to include a Wistia video into your WordPress website with shortcode. While our shortcode is very basic, we do expect to improve upon it to make the most of the API features . At this stage, however, we just wanted something basic; we'll improve upon it soon.

If we continue with Wistia - and we expect that we will - we'll build a module into our Platform to render the analytics, and we'll also integrate the features with other marketing modules of the Platform. Update, October 2020: Wistia is now fully integrated into our Digital Marketing and Social Media System. Clients should refer to this article which details how it is used.

Our simple shortcode supports basic inline embeds, text link popups, and thumbnail image popups.

The Result

Inline Video

To embed a basic inline video, use [wistia v="bfflqddp8w"][/wistia]. The result is as follows:

Text Link Popup

To show plain text that launches a popup, use [wistia v="bfflqddp8w" popup="1"]your text in here[/wistia], with a result of your text in here. Other than text you can also use images and other objects. The text you use may also be a shortcode itself.

Image Link Popup

To show your video thumbnail that launches a popup, use [wistia v="bfflqddp8w" popup="1"][/wistia]. The result:

 

In this case I've reference my own image placeholder with the attribute of image="https://www.beliefme... matrix-map.jpg".

WordPress Shortcode

Our shortcode doesn't come close to being complete. If you're interested in the inevitable update, follow us on Facebook or join our mailing list.

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

1
<?php 
2
/*
3
 Embed Wistia Videos In WordPress With Shortcode
4
 https://www.beliefmedia.com.au/wistia-wordpress-shortcode
5
*/
6
 
7
function beliefmedia_wistia_video($atts, $content = null) {
8
 
9
  $atts = shortcode_atts(array(
10
    'v'  => '',
11
    'width'  => '560',
12
    'height'  => 0,
13
    'seo'  => 0,
14
    'popup' => 0,
15
    'animate' => 1,
16
    'quality' => '540', /* 224, 360, 540, 720, 1080, 3840 */
17
    'qualitycontrol' => 'true',
18
    'qualitymin' => 'true', /* 224, 360, 540, 720, 1080, 3840 */
19
    'image' => 0,
20
    'playbutton' => 'true',
21
    'smallplaybutton' => 'false',
22
    'color' => '#FFB45D',
23
    'playbar' => 'true',
24
    'fullscreenbutton' => 'true',
25
    'tracking' => 'true',
26
    'autoplay' => 'false',
27
    'googleanalytics' => 'true',
28
    'backgroundopacity' => '0.91',
29
  ), $atts);
30
 
31
  /* If a URL we'll get the ID. Best to provide just ID */
32
  if (strripos($atts['v'],'http') !== false) {
33
    $regex = '/(https?:\/\/)?(www\.)?wistia\.com\/medias\/(a-zA-Z0-9)*/';
34
    preg_match($regex, $atts['v'], $m);
35
    $atts['v'] = $m[4];
36
  }
37
 
38
  /* Get email of user. Need to pass in URL */
39
  $atts['email'] = $_GET['wistia_bm_email'];
40
  if (!filter_var($atts['email'], FILTER_VALIDATE_EMAIL)) $atts['email'] = '';
41
 
42
  /* Scale the height if not defined */
43
  if (!$atts['height']) $atts['height'] = round($atts['width']/1.777);
44
 
45
  /* Build Options */
46
  $options = 'qualityControl=' . $atts['qualityControl'] . ' qualityMin=' . $atts['qualitymin'] . ' smallPlayButton=' . $atts['smallplaybutton'] . ' playerColor=' . $atts['color'] . ' playButton=' . $atts['playbutton'] . ' playbar=' . $atts['playbar'] . ' fullscreenButton=' . $atts['fullscreenbutton'] . ' autoPlay=' . $atts['autoplay'] . ' googleAnalytics=' . $atts['googleanalytics'] . ' backgroundOpacity=' . $atts['backgroundopacity'];
47
  if ($atts['image']) $options .= ' stillUrl=' . $atts['image'];
48
  if ($atts['email'] != '') $options .= 'email=' . $atts['email'];
49
  $options .= (is_user_logged_in() === false) ? ' doNotTrack=' . $atts['tracking'] : ' doNotTrack=true';
50
 
51
  /* Build embed code */
52
  $return = '<script src="https://fast.wistia.com/embed/medias/' . $atts['v'] . '.jsonp" async></script><script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>';
53
 
54
  if (!$atts['popup']) {
55
 
56
    $return .= '<div class="wistia_responsive_padding" style="padding:56.25% 0 0 0;position:relative;">
57
<div class="wistia_responsive_wrapper" style="height:100%;left:0;position:absolute;top:0;width:100%;">
58
<div class="wistia_embed wistia_async_' . $atts['v'];
59
    if (!$atts['seo']) $return .= ' seo=false';
60
    $return .= ' videoFoam=true ' . $options . '" style="height:100%;position:relative;width:100%"><div class="wistia_swatch" style="height:100%;left:0;opacity:0;overflow:hidden;position:absolute;top:0;transition:opacity 200ms;width:100%;"><img src="https://fast.wistia.com/embed/medias/' . $atts['v'] . '/swatch" style="filter:blur(5px);height:100%;object-fit:contain;width:100%;" alt="" onload="this.parentNode.style.opacity=1;" /></div>
61
</div>
62
</div>
63
</div>';
64
    $frame = true;
65
 
66
  } elseif ($atts['popup'] && $content == '') {
67
 
68
    /* Thumbnail Popup */
69
    $animate = ($atts['animate']) ? 'true' : 'false';
70
    $return .= '<div class="wistia_responsive_padding" style="padding:56.25% 0 0 0;position:relative;">
71
<div class="wistia_responsive_wrapper" style="height:100%;left:0;position:absolute;top:0;width:100%;"><span class="wistia_embed wistia_async_' . $atts['v'] . ' popover=true popoverAnimateThumbnail=' . $animate . ' videoFoam=true ' . $options . '" style="display:inline-block;height:100%;position:relative;width:100%"> </span></div>
72
</div>';
73
    $frame = true;
74
 
75
  } else {
76
 
77
    /* Text Popup */
78
    $return .= '<span class="wistia_embed wistia_async_' . $atts['v'] . ' popover=true popoverContent=link ' . $options . '" style="display:inline;position:relative"><a href="#">' . do_shortcode($content) . '</a></span>';
79
    $frame = false;
80
  }
81
 
82
 return ($frame !== false) ? '<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: ' . $atts['width'] . 'px;  margin: 0px auto;>' . $return . '</div>' : $return;
83
}
84
add_shortcode('wistia', 'beliefmedia_wistia_video');

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 shortcode attributes listed here are only a small number of those available. When we work out how we'll be using Wistia we'll revisit and rewrite our code.

v

The v is the video ID. The format of a video URL in Wistia looks as follows: https://YourUsername.wistia.com/medias/xxxx, where xxxx is the video ID.

width

By default Wistia renders a video width as either fixed or responsive to 100% (full width). We've added a responsive container so you can include a responsive video at an initial width of your choosing. Usage: width="520".

height

The video height is automatically calculated to fit a normal HD ratio of 16:9. If this doesn't work for you, set the height yourself.

seo

If set to true, the video's metadata will be injected into the page's on-page markup. Set it to false if you don't want seo metadata injection. More information is available from Wistia's SEO page . It's true by default.

popup

To launch the video in a popup, use popup="1" (the video embeds and plays inline by default).

animate

When using a popup and the video thumbnail is rendered rather than the video object, an animation will play on mouseover. To remove the animation use animation="false". Default: true.

quality

Set the intial quality of the video playback by using quality="540", where 540 is any one of the following: 224, 360, 540, 720, 1080, 3840. The user will still be able to alter their quality once playback starts unless qualitycontrol (below) is set to false.

qualitycontrol

To prevent a user from adjusting the quality of the video that plays to them, use qualitycontrol="false" (true by default).

qualitymin

Setting a qualitymin allows you to specify the minimum quality the video will play at. Wistia will still run bandwidth checks to test for speed, and play the highest quality version at or above the set minimum. Accepted values: 224, 360, 540, 720, 1080, 3840.

image

If you choose to alter the video placeholder, use image="https://www.beliefmedia.com/full-url-to-image.jpg". The image should be scaled to fit your video.

playbutton

If set to true, the big play button control will appear in the center of the video before play.

smallplaybutton

If set to true, the small play button control will be available.

color

Changes the base color of the player. Expects a hexadecimal rgb string like "ff0000" (red), "000000" (black), "ffffff" (white), or "0000ff" (blue). There's a large number of options to alter the player container, and we only included a few options for this basic shortcode.

playbar

If set to true, controls like the big play button, playbar, volume, etc. will be visible as soon as the video is embedded. Default is true. On mobile devices, this option has no effect (beyond hiding/showing the big play button) because the player will be using native controls.

fullscreenbutton

If set to true, the fullscreen button will be available as a video control. Default: true.

tracking

By default, data for each viewing session is tracked and reported back to the Wistia servers for display in heatmaps and aggregation graphs. If you do not want to track viewing sessions, set tracking="false". Default: true. If you're logged into WordPress tracking is false to avoid corrupting your playback data with your own interactions.

autoplay

If set to true, the video will play as soon as it's ready. Default: false.

googleanalytics

If you're using Google Analytics on the page where you embed a video, the video will auto-magically send events to your Google Analytics account. If you don't want a video to send those events to Google Analytics, use googleanalytics="false". Default: true.

backgroundopacity

A decimal between 0 and 1 to set the overall opacity of the background. Default is 0.91.

email

Email is normally an attribute but we've included the feature by default. This enables you to pass the user email as a parameter in your page URL (as wistia_bm_email=user@someemail.com) and that email will be associated with the viewer in your dashboard, and will also be made available for analysis via the API. To retrieve a modified URL query string in WordPress, you'll have to use theadd_query_arg function or another means to parse the query string. This is an extremely powerful marketing feature that permits you to email those that interact with your content in various ways.

Considerations

  • If you're serious about your video marketing efforts, a platform like Wistia is almost essential... until, of course, YouTube makes data available that they already collect. If YouTube were to make more information available, and they provided just a few additional features for marketing purposes, their platform will be unrivaled.
  • Full details on Wistia's embed options are available here . API documentation is available here . We've only detailed a small part of Wistia's service.
  • If you're looking to try the service for yourself, Wistia provides a free option that includes three videos and 200GB of monthly bandwidth.
  • Wistia supports an iframe embed as an alternative to their preferred method. Details are on their website (we've not provided that feature in the shortcode).

Download


Title: Embed Wistia Videos In WordPress With Shortcode
Description: Embed Wistia videos in a WordPress post of page with basic shortcode. Shows videos inline of via a popup modal.
  Download • Version 0.1, 1.7K, zip, Category: WordPress Shortcodes

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment