Drupal Tech Talk: Low impact Youtube / Vimeo implementation

15 Apr 2014

Joris Snoek
Digital Consultant
+31 (0)20 - 261 14 99

Our Drupal Tech blog is English, so the whole world can enjoy it :)

If you want to publish a Youtube -or Vimeo video in your Drupal website, you can use the Media:Youtube module. But then you'll add lot of overhead to your Drupal system; this is a light weight alternative, for ya Drupal coders out there.

Step 1. Add a text field

For example in content type Blog you add a field 'Blog video' with system name 'field_blog_video‎' type 'text', widget 'Text Field".
drupal blog video

Step 2. Add function

For example in your template.php file.

function _MYTHEME_convert_video_to_embed($url, $width, $height) {
if (strpos($url, 'youtube')) {
$find = 'watch?v=';
$pos = strpos($url, $find);
$iframe = '

elseif (strpos($url, 'vimeo')) {
$find = 'http://vimeo.com/';
$pos = strpos($url, $find);
$iframe = '

else {
return '';
return $iframe;


Step 3. Call this function in a tpl.php file

For example in node-blog.tpl.php

// Fill out variables
$url = $content['field_blog_video']['#items'][0]['value'];
$width = 560;
$height = 315;

// Print the shizzle
print _MYTHEME_convert_video_to_embed($url, $width, $height);


Step 4. Done!

Have a bear



Nóg meer
kennis nodig?

Check ons ons blog archief >