Change width and height in oembed code on the fly WP 2.9

von Joern am 21. Dez. 2009 | Keine Kommentare

As explained in a previous topic get the oembed code of a video in a WP 2.9 post from postmeta we can get only the code for embeded media (WordPress 2.9 required!)
To change and resize the width and height of the video we are going to display, we can add a function to the theme’s function.php to do this for us.

I got this function from Vinod Kumar explained here:

Dynamically Change Width and Height in embed code
So put this function into your functions.php first:

// the function to resize oembed videos
function resizeMarkup($markup, $dimensions)
$w = $dimensions[‚width‘];
$h = $dimensions[‚height‘];

$patterns = array();
$replacements = array();
if( !empty($w) )
$patterns[] = ‚/width="([0-9]+)"/‘;
$patterns[] = ‚/width:([0-9]+)/‘;

$replacements[] = ‚width="‘.$w.’"‘;
$replacements[] = ‚width:‘.$w;

if( !empty($h) )
$patterns[] = ‚/height="([0-9]+)"/‘;
$patterns[] = ‚/height:([0-9]+)/‘;

$replacements[] = ‚height="‘.$h.’"‘;
$replacements[] = ‚height:‘.$h;

return preg_replace($patterns, $replacements, $markup);
Having this code activated by putting it in functions.php, we can use it as explained in Vinod’s post (link above).
We want to use this function to change width and height attributes throughout the oembed code we retrieved before from the WordPress database.

As explained here: viewtopic.php?f=1&t=51 we have already a variable assigned to the oembed code, now we just pass this variable to the function ‚resizeMarkup‘ with new values for width and height and echo the resized video clip.

To do this we put into the loop this code:

<?php if(function_exists(‚resizeMarkup‘)) {
$resizedvideo = resizeMarkup(($embedhtml), array(
‚height’=>250 ));
echo $resizedvideo; } ?>
Any questions? Sign up and ask, you are welcome.
you find me on Google+, Twitter and Facebook

(von: master)

Sorry, no posts matched your criteria.


Du findest mich auch auf Twitter und Facebook!

Schreibe einen Kommentar

Pflichtfelder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.

weitere forum Beiträge: