RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Embed Dailymotion Videos in WordPress with Shortcode

Founded in 2005, DailyMotion now has an Alexa score of 83 and is ranked as one of the largest and most profitable video sharing websites in the world. This article will show you how to embed responsive DailyMotion videos in WordPress with shortcode.

The site hosts pornographic content so visiting the service should be done so discreetly.

The Result

The result of our shortcode will render a video container as follows.

The video is responsive so will play nice on mobile devices.

Shortcode Usage

To include the video on your post or page, you should do so by including the video ID (obtained from the URL), or the entire video URL, into our shortcode as follows:

[dailymotion v="x2nvui2" width="580"] or [dailymotion v="http://www.dailymotion.com/video/x2nvui2_sir-james-galway-masterclass-practicing-scales_music" width="580"]

I've defined the video width into my shortcode. This wouldn't be necessary if the width was hard coded into your shortcode function. The height will automatically be determined and applied. If the height doesn't work for you, define it in your shortcode.

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
 Show DailyMotion Videos in a WordPress Post or Page with Shortcode
4
 http://www.beliefmedia.com/code/wp-snippets/embed-dailymotion-wordpress
5
*/
6
 
7
function beliefmedia_embed_dailymotion($atts) {
8
 
9
  $atts = shortcode_atts(array(
10
    'v'  => '',
11
    'width'  => '540',
12
    'height' => 0
13
  ), $atts);
14
 
15
  /* Scale the height if not defined */
16
  if (!$atts['height']) $atts['height'] = round($atts['width'] / 1.778);
17
 
18
  /* If a URL we'll snatch the ID. Best to provide just ID */
19
  if (strripos($atts['v'], 'http') !== false) {
20
    $regex = '/video\/([^_]+)/';
21
    preg_match($regex, $v, $m);
22
    $v = $m[1];
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
     }
45
   </style>
46
 
47
';
48
 
49
   /* Build iframe */
50
   $iframe = '<iframe frameborder="0" width="' . $atts['width'] . '" height="' . $atts['height'] . '" src="//www.dailymotion.com/embed/video/' . $atts['v'] . '" scrolling="no" allowfullscreen></iframe>';
51
 
52
 /* Return responsive iframe */
53
 return '<div style="max-width: ' . rtrim($atts['width'], 'px') . 'px; margin: 0px auto;">' . $style . '<div class="embed-container">' . $iframe . '</div>
54
</div>';
55
}
56
add_shortcode('dailymotion', 'beliefmedia_embed_dailymotion');

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

  • You will find the video ID in the video URL. While you can use the entire video URL, best practice would have you only include the actual video ID in case the URL changes in the future.
  • DailyMotion hosts an array of content you wouldn't normally see on commercial platforms such as YouTube. Because of the pornography-related material and what has been seen as ISIS propaganda, it isn't the best pick of website for your cat videos.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

Like this article?

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

Leave a comment