Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggreagtion Enquires Welcome

Embed uStream Video With PHP or WordPress Shortcode

Ustream is a company that provides video streaming services to more than 80 million viewers and broadcasters. Founded in 2007, it's now one of the most frequented websites for live or streaming video. This post will show you how to render responsive uStream videos into your WordPress post or page with shortcode. There's a PHP function for use outside of WordPress.

The Result

Shortcode of [ustream v="40478440"] (just the video ID), [ustream v="https://www.ustream.tv/recorded/40478440"] (the video ULR), or the actual embed URL of [ustream v="https://www.ustream.tv/embed/recorded/40478440"], all render the following into your WordPress website.

Shortcode Attributes

v

As stated, v is virtually any URL that references a particular video. It's best to use just the video ID since we strip all other characters from the URL string (regardless of how it's formatted) before rebuilding it.

width

The width in the shortcode function should be adjusted so that the video container fits nicely into the content area of your own website.

height

The height will automatically be scaled based on the width. The option to define the height for each video remains.

color

The color of the player controls can be set to red, green, pink, orange, or left blank (which renders the default uStream blue). These colors match up with the options available if you were to directly copy the messy embed code. Use like ustream v="40478440" color="red".

Embed uStream Video With PHP or WordPress Shortcode

Copying embed code with color options. The long way...

WordPress Shortcode

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

1
<?php 
2
/*
3
    Embed uStream Video With PHP or WordPress Shortcode
4
    http://www.beliefmedia.com/ustream-wordpress
5
    Permitted colors are red, green, pink & orange, or left blank for blue (default)
6
*/
7
 
8
function beliefmedia_ustream_video($atts) {
9
10
  'v'  => '',
11
  'width'  => '560',
12
  'height'  => '',
13
  'color'  => ''
14
 ), $atts));
15
 
16
  /* If no height is defined... */
17
  if (!$height) $height = round($width / 1.58);
18
 
19
   /* Whether embed or video URL, we'll get video ID */
20
   if (strpos($v,'http') !== false) {
21
    $id = substr($v, strrpos($v, '/') + 1);
22
    $v = trim($id);
23
   }
24
 
25
   /* Color html for embed code */
26
   switch ($color) {
27
    case "red":
28
     $c = 'ff3d23';
29
     break;
30
    case "green":
31
     $c = '85a901';
32
     break;
33
    case "pink":
34
     $c = 'e166b7';
35
     break;
36
    case "orange":
37
     $c = 'ff720a';
38
     break;
39
   }
40
 
41
   $style = '<style scoped>
42
    .embed-container { 
43
      position: relative;
44
      padding-bottom: ' . round(($height / $width) * 100) . '%;
45
      height: 0; 
46
      overflow: hidden;
47
      max-width: ' . $width . 'px;
48
      margin: 0px auto;
49
    } 
50
 
51
    .embed-container iframe { 
52
      position: absolute;
53
      top: 0px;
54
      left: 0px;
55
      width: 100%;
56
      height: 100%;
57
      padding-bottom: 0;
58
    }</style>';
59
 
60
  /* Build iframe */
61
  $return .= '<iframe width="' . $width . '" height="' . $height . '" src="https://www.ustream.tv/embed/recorded/' . $v . '?';
62
  if ($color) $return .= 'ub=' . $c . '&lc=' . $c . '&oc=ffffff&uc=ffffff&';
63
  $return .= 'v=3&wmode=direct" scrolling="no" frameborder="0"></iframe>';
64
 
65
 /* Responsive iframe */
66
 return '<p><div>' . $style . '<div class="embed-container">' . $return . '</div></div></p>';
67
}
68
add_shortcode('ustream', 'beliefmedia_ustream_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.

Download

Title: Embed uStream Video in WordPress (WordPress Plugin)
Description: Embed responsive uStream videos in WordPress with shortcode.
  Download • Version 0.2, 1.9K, zip, Category: WordPress Plugins (General)
WordPress Shortcodes, (1.0K)    

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment

READY TO HAVE A CHAT? CALL US ANYTIME ON 1300 235 433