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 Yahoo! News Videos With PHP or WordPress Shortcode

Embed Yahoo! News Videos With PHP or WordPress Shortcode

Yahoo! News originated as an internet-based news aggregator by Yahoo!. By 2011, however, Yahoo had expanded its focus to include original content, as part of its plans to become a major media organization. Integrating veteran journalists such as Walter Shapiro, Virginia Heffernan, and Katie Couric has slowly given the service more credibility than it originally deserved. According to Alexa , the site currently sits in 12th position for news consumption - ahead of the likes of FOX, Bloomberg, Reuters, WSJ, and others.

Note: Yahoo News and other videos are no longer supported.

The WordPress function on this page will permit you to embed responsive Yahoo! News videos into your WP post or page with shortcode. We've also provided a PHP function for use outside of WordPress.

The function may work on Yahoo! videos other than news videos but we've found their platform to be notoriously unreliable.

The Result

The shortcode of [yahoonews v="https://news.yahoo.com/video/yahoo-news-live-ben-carson-182500280.html"] will render the following video :

[yahoonews v="https://news.yahoo.com/video/yahoo-news-live-ben-carson-182500280.html"]

Available attributes are v (the full video URL), and width. The height will automatically be determined.

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 Yahoo! News Videos With PHP or WordPress Shortcode
4
 http://www.beliefmedia.com/yahoo-news-video
5
*/
6
 
7
function beliefmedia_yahoo_news_video($atts) {
8
 
9
  $atts = shortcode_atts(array(
10
    'v'  => '', /* Full Page URL */
11
    'width'  => '540',
12
    'height' => false
13
  ), $atts);
14
 
15
  /* Strip search queries etc */
16
  if (strripos($atts['v'], '?') !== false) $v = substr($atts['v'], 0, strrpos($atts['v'], '?'));
17
  $atts['v'] = str_replace('video-search/', '', $atts['v']);
18
 
19
  /* Scale the height if not defined */
20
  if ($atts['height'] === false) $atts['height'] = round($atts['width']/1.778);
21
 
22
   $style = '
23
<style scoped>
24
    .embed-container {
25
      position: relative;
26
      padding-bottom: ' . round(($atts['height'] / $atts['width']) * 100) . '%;
27
      height: 0;
28
      overflow: hidden;
29
      max-width: ' . $atts['width'] . 'px;
30
      margin: 0px auto;
31
    }
32
 
33
    .embed-container iframe {
34
      position: absolute;
35
      top: 0px;
36
      left: 0px;
37
      width: 100%;
38
      height: 100%;
39
      padding-bottom: 0;
40
    }</style>
41
 
42
';
43
 
44
  /* Build iframe */
45
  $iframe = '<iframe width="' . $atts['width']  . '" height="' . $atts['height']  . '" scrolling="no" frameborder="0" src="' . $atts['v'] . '?format=embed" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" allowtransparency="true"></iframe>';
46
 
47
 /* Responsive iframe */
48
 return '<div style="max-width: ' . $atts['width'] . 'px; margin: 0px auto;">' . $style . '<div class="embed-container">' . $iframe . '</div>
49
</div>';
50
}
51
add_shortcode('yahoonews', 'beliefmedia_yahoo_news_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.

PHP Function

The following function may be used outside of WordPress. Not unlike the WP version, the video will be responsive.

1
<?php 
2
/*
3
 Embed Yahoo! News Videos With PHP or WordPress Shortcode
4
 http://www.beliefmedia.com/yahoo-news-video
5
*/
6
 
7
function beliefmedia_yahoo_news_video($v, $width = '540', $height = false) {
8
 
9
  /* Strip search queries etc */
10
  if (strripos($v, '?') !== false) $v = substr($v, 0, strrpos($v, '?'));
11
  $v = str_replace('video-search/', '', $v);
12
 
13
  /* Scale the height if not defined */
14
  if ($height === false) $height = round($width/1.778);
15
 
16
   $style = '
17
<style scoped>
18
    .embed-container {
19
      position: relative;
20
      padding-bottom: ' . round(($height / $width) * 100) . '%;
21
      height: 0;
22
      overflow: hidden;
23
      max-width: ' . $width . 'px;
24
      margin: 0px auto;
25
    }
26
 
27
    .embed-container iframe {
28
      position: absolute;
29
      top: 0px;
30
      left: 0px;
31
      width: 100%;
32
      height: 100%;
33
      padding-bottom: 0;
34
    }</style>
35
 
36
';
37
 
38
  /* Build iframe */
39
  $iframe = '<iframe width="' . $width  . '" height="' . $height  . '" scrolling="no" frameborder="0" src="' . $v . '?format=embed" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" allowtransparency="true"></iframe>';
40
 
41
 /* Responsive iframe */
42
 return '<div style="max-width: ' . $width . 'px; margin: 0px auto;">' . $style . '<div class="embed-container">' . $iframe . '</div>
43
</div>';
44
}
45
 
46
/* Usage */
47
$v = 'https://news.yahoo.com/video/yahoo-news-live-ben-carson-182500280.html';
48
echo beliefmedia_yahoo_news_video($v);

Considerations

  • When pasting video URLs into the shortcode, try and remove everything after the .html. This accounts for URL structures we haven't seen.

Download

No longer available.

■ ■ ■

 
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 ]

RELATED READING

Like this article?

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

Leave a comment