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

Embed FunnyOrDie Videos in a WordPress Post or Page With Shortcode

Funny or Die (FOD) is an Emmy-winning comedy video website founded by Will Ferrell and Adam McKay's production company, Gary Sanchez Productions , with original and user-generated content. This article will show you how to include responsive FOD videos in your WordPress post or page with shortcode.

The Result

If I were to include this video I would use the shortcode of [funnyordie v="https://www.funnyordie.com/videos/74/the-landlord-from-will-ferrell-and-adam-ghost-panther-mckay"] or simply [funnyordie v="74"] (just the video ID). The responsive result is as follows.

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 FunnyOrDie Videos in a WordPress Post or Page With Shortcode
4
 http://www.beliefmedia.com/funny-or-die-wordpress
5
*/
6
 
7
function beliefmedia_funnyordie_video($atts, $content = null) {
8
  $atts = shortcode_atts(array(
9
    'v'  => '',
10
    'width'  => '580',
11
    'height' => '',
12
    'frameborder' => '0',
13
    'align' => 'center'
14
  ), $atts);
15
 
16
  /* If a URL we'll snatch the ID. Best to provide just ID */
17
  if (strripos($atts['v'], 'http') !== false) {
18
    $regex = '/videos\/([^_]+)\//';
19
    preg_match($regex, $atts['v'], $m);
20
    $atts['v'] = $m[1];
21
  }
22
 
23
  /* Scale the height if not defined : FOD default 640 x 400 */
24
  if (!$atts['height']) $atts['height'] = round($atts['width'] / 1.6);
25
 
26
  $style = '
27
<style scoped>
28
    .embed-container {
29
      position: relative;
30
      padding-bottom: ' . round(($atts['height'] / $atts['width']) * 100) . '%;
31
      height: 0;
32
      overflow: hidden;
33
      max-width: ' . $atts['width'] . 'px;
34
      margin: 0px auto;
35
    }
36
 
37
    .embed-container iframe {
38
      position: absolute;
39
      top: 0px;
40
      left: 0px;
41
      width: 100%;
42
      height: 100%;
43
      padding-bottom: 0;
44
      overflow: hidden;
45
   }</style>
46
 
47
';
48
 
49
   /* iFrame */
50
   $iframe = '<iframe loading="lazy" src="https://www.funnyordie.com/embed/' . $atts['v'] . '" width="' . $atts['width'] . '" height="' . $atts['height'] . '" frameborder="' . $atts['frameborder'] . '" allowfullscreen webkitallowfullscreen mozallowfullscreen scrolling="no"></iframe>';
51
 
52
 /* Return responsive iframe */
53
 return '<div style="max-width: ' . $atts['width'] . 'px; margin: 0px auto;">' . $style . '<div class="embed-container">' . $iframe . '</div>
54
</div>';
55
}
56
add_shortcode('funnyordie', 'beliefmedia_funnyordie_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

v

The video ID is either the full video URL or simply the numeric video ID (preferred).

width

The width of the video container.

height

The height of the video container is automatically determined so may be left blank. If formatting requires its inclusion, simply include it in your shortcode.

Considerations

  • Most of the FOD videos are also on YouTube. However, you'll lose the integrated features of the default FOD player.

Download


Title: Embed FunnyOrDie Videos in WordPress
Description: Embed FunnyOrDie Videos in a WordPress Post or Page With Shortcode.
  Download • Version 0.2, 1.0K, 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.

  AUS Eastern Standard Time (Virginia)

  Want to have a chat?
 

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