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 LiveLeak Videos in a WordPress Post or Page with Shortcode

In the video hosting world, LiveLeak is like a social sewer; it hosts graphic, pornographic, and other videos that violate about every other website term of service. The confronting videos that LiveLeak makes a habit of hosting include the execution of James Foley, the anti-Quran film Fitna, and the execution of Suddam Hussein... with website founders sticking to their (commercially motivated?) mantra of permitting free speech, or "redefining the media" .

Note: This shortcode is no longer valid and will be replace soon.

Founded in 2006, the site claims that they aim to take reality footage, politics, war, and other world events and combine them with the power of citizen journalism. At the time of writing the site is the 642nd most popular website globally.

The popularity of LiveLeak isn't reflected in their less-than-ideal aesthetics and mobile presence, and the rich sharing options on other similar websites are far superior to those on LiveLeak.

In an effort to generate shortcode that'll render LiveLeak videos, we're required to take a rather unconventional approach and scrape the LiveLeak video page for the relevant embed information. However, once the LiveLeak website is scraped for a particular video ID, we don't query that page again.

The code on this page isn't ideal... but it's about the best option available, and it's still more scalable than using video specific embed code on every post or page where a LiveLeak video is required.

The Result

Using the shortcode of [liveleak v="https://www.liveleak.com/view?t=CaxYd_1604820065"] or just [liveleak v="CaxYd_1604820065"] we'll render a LiveLeak video as follows:

[liveleak v="https://www.liveleak.com/view?t=CaxYd_1604820065"]

Shortcode Attributes

v

Use [liveleak v="http://www.liveleak.com/view?i=100_1338007444"] or just [liveleak v="100_1338007444"]. Using just the video ID is preferred.

width

The width is the width of your embedded video. Alter the default "560" in the shortcode function for the width of your own WordPress post container. The video is responsive so will scale to mobile devices.

height

The video height (or height) doesn't need to be defined unless our auto scaling isn't suitable. We'll automatically create a video height based on your defined width.

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 Liveleak Videos in a WordPress Post or Page with Shortcode
4
 http://www.beliefmedia.com/code/wp-snippets/liveleak-wordpress-shortcode
5
*/
6
 
7
function beliefmedia_wordpress_liveleak($atts) {
8
 
9
  $atts = shortcode_atts(array(
10
    'v' => '', /* Video URL */
11
    'width' => '560',
12
    'height' => ''
13
  ), $atts);
14
 
15
  /* Post ID */
16
  global $post;
17
  $id = $post->ID;
18
 
19
  /* If a URL we'll snatch the ID. Best to provide just ID */
20
  if (strripos($atts['v'], 'http') !== false) {
21
    $str = parse_url($atts['v'], PHP_URL_QUERY);
22
    parse_str($str, $params);
23
    $atts['v'] = $params['i'];
24
  }
25
 
26
  /* If no height defined... */
27
  if (!$atts['height']) $atts['height'] = round($atts['width'] / 1.77);
28
 
29
  /* Video Key */
30
  $transient = 'bmleak_' . md5($atts['v']);
31
 
32
  if ( (get_post_meta($id, $transient, true)) != '') {
33
   $video_id = get_post_meta($id, $transient, true);
34
 
35
   } else {
36
 
37
    /* Get liveleak page and extract embed ID */
38
    $result = file_get_contents('https://www.liveleak.com/view?i=' . $atts['v']);
39
 
40
    /* Basic match to get video embed ID */
41
    preg_match('/ll_embed\?f=(.*)" frameborder="0"/', $result, $m);
42
    $video_id = $m[1];
43
 
44
    /* Save video embed ID to DB */
45
    add_post_meta($id, $transient, $videoid);
46
   }
47
 
48
   $style = '
49
<style scoped>
50
     .embed-container {
51
       position: relative;
52
       padding-bottom: ' . round(($atts['height'] / $atts['width']) * 100) . '%;
53
       height: 0;
54
       overflow: hidden;
55
       max-width: ' . $atts['width'] . 'px;
56
       margin: 0px auto;
57
     }
58
 
59
     .embed-container iframe {
60
       position: absolute;
61
       top: 0px;
62
       left: 0px;
63
       width: 100%;
64
       height: 100%;
65
       padding-bottom: 0;
66
       overflow: hidden;
67
     }
68
   </style>
69
 
70
';
71
 
72
  /* Build iframe */
73
  $iframe = '<iframe width="' . $atts['width'] . '" height="' . $atts['height'] . '" src="https://www.liveleak.com/ll_embed?f=' . $video_id . '" frameborder="0" scrolling="no" allowfullscreen></iframe>';
74
 
75
 /* Return responsive iframe */
76
 return '<div style="max-width: ' . $atts['width'] . 'px; margin: 0px auto;">' . $style . '<div class="embed-container">' . $iframe . '</div>
77
</div>';
78
}
79
add_shortcode('liveleak', 'beliefmedia_wordpress_liveleak');

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

  • As stated, the expression to find the video embed ID isn't ideal. If the page HTML changes please let us know and we'll update the code.

■ ■ ■

 
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