RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts</strong | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.69% (5.89%*) • Home Loan Fixed: 5.39% (6.59%*) • Fixed: 5.39% (6.59%*) • Variable: 5.69% (5.89%*) • Investment IO: 5.69% (6.48%*) • Investment PI: 5.39% (6.59%*)

Embed MetaCafe Videos in a WordPress Post or Page with Shortcode

Metacafe is a video-sharing website that specialises in short-form video entertainment. Founded in July 2003 in Israel, Metacafe now ranks around the 1200 mark on Alexa , and the site maintains a significant presence in the video sharing space. This article will show you how to include responsive Metacafe videos on your WordPress post or page with shortcode.

Note: This code no longer seems to work and is due for an update.

The Result

Using the shortcode of [metacafe v="11555883"] (using the video ID obtained from each video URL) or [metacafe v="http://www.metacafe.com/watch/11555883/daddy-scares-her-little-girl-with-shadow-monster/"] (the full video URL), the following video will be returned:

[metacafe v="11555883"]

As with other shortcode we've provided, it's generally best practice to use the video ID rather than the full URL.

Shortcode Parameters

v

The video ID or full video URL.

width

The numeric width of your video in pixels (generally just under the total width of your post container).

height

The height of your video will automatically be determined based on the width. However, if required, it can be defined.

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.

1
<?php 
2
/*
3
 Embed MetaCafe Videos in a WordPress Post or Page with Shortcode
4
 http://www.beliefmedia.com/code/metacafe-wordpress-shortcode
5
*/
6
 
7
function beliefmedia_embed_metacafe($atts) {
8
 
9
  $atts = shortcode_atts(array(
10
    'v'  => '',
11
    'width'  => '540',
12
    'height' => false
13
  ), $atts);
14
 
15
  /* Scale the height if not defined */
16
  if ($atts['height'] === false) $atts['height'] = round(abs($atts['width'])/1.777);
17
 
18
  /* If a URL we'll snatch the ID. Best to provide just ID */
19
  if (strripos($atts['v'], 'http') !== false) {
20
    $path = parse_url($atts['v'], PHP_URL_PATH);
21
    $pieces = explode('/', $path);
22
    $atts['v'] = $pieces[2];
23
  }
24
 
25
  $style = '
26
<style scoped>
27
    .embed-container {
28
      position: relative;
29
      padding-bottom: ' . round(($atts['height'] / $atts['width']) * 100) . '%;
30
      height: 0;
31
      overflow: hidden;
32
      max-width: ' . $atts['width'] . 'px;
33
      margin: 0px auto;
34
    }
35
 
36
    .embed-container iframe {
37
      position: absolute;
38
      top: 0px;
39
      left: 0px;
40
      width: 100%;
41
      height: 100%;
42
      padding-bottom: 0;
43
      overflow: hidden;
44
   }</style>
45
 
46
';
47
 
48
  $iframe = '<iframe width="' .  $atts['width'] . '" height="' . $atts['height'] . '" src="http://www.metacafe.com/embed/' . $atts['v'] . '/" frameborder="0" scrolling="no" allowfullscreen></iframe>';
49
 
50
  /* Return responsive iframe */
51
 return '<div style="max-width: ' . $atts['width'] . 'px; margin: 0px auto;">' . $style . '<div class="embed-container">' . $iframe . '</div>
52
</div>';
53
}
54
add_shortcode('metacafe', 'beliefmedia_embed_metacafe');

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.

Considerations

  • Metacafe has a habit of providing a vertical scrollbar on each video that it renders via an iframe. For that reason, I've added scrolling="no" to the final code avoid them. The video won't be affected.
  • If you can embed the same video from YouTube or any other reliable source, it's best to do so to avoid the annoying auto-start preroll adverts.

Download

Removed

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

Like this article?

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

Leave a comment