<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
		>
	<channel>
		<title>Wordpress and Webdesign Forum go41 &#187; Topic: Change width and height in oembed code on the fly WP 2.9</title>
		<link>http://forum.go41.de/topic/change-width-and-height-in-oembed-code-on-the-fly-wp-29</link>
		<description>How To, tips, php and css code for your WordPress site</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 22:53:36 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.1</generator>
				<atom:link href="http://forum.go41.de/rss/topic/change-width-and-height-in-oembed-code-on-the-fly-wp-29" rel="self" type="application/rss+xml" />

		<item>
			<title>masteradmin on "Change width and height in oembed code on the fly WP 2.9"</title>
			<link>http://forum.go41.de/topic/change-width-and-height-in-oembed-code-on-the-fly-wp-29#post-102</link>
			<pubDate>Mon, 21 Dec 2009 14:41:07 +0000</pubDate>
			<dc:creator>masteradmin</dc:creator>
			<guid isPermaLink="false">102@http://forum.go41.de/</guid>
			<description><![CDATA[<p>As explained in a previous topic <a href="http://forum.go41.de/topic/get-the-oembed-code-of-a-video-in-a-wp-29-post-from-postmeta">get the oembed code of a video in a WP 2.9 post from postmeta</a> we can get only the code for embeded media (WordPress 2.9 required!)</p>
<p>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.<br />
I got this function from Vinod Kumar explained here:<br />
<a href="http://scvinodkumar.wordpress.com/2009/08/14/dynamically-change-width-and-height-in-embed-code/">Dynamically Change Width and Height in embed code</a></p>
<p>So put this function into your functions.php first:<br />
<pre><code>// the function to resize oembed videos
function resizeMarkup($markup, $dimensions)
{
$w = $dimensions[&#39;width&#39;];
$h = $dimensions[&#39;height&#39;];

$patterns = array();
$replacements = array();
if( !empty($w) )
{
$patterns[] = &#39;/width=&#34;([0-9]+)&#34;/&#39;;
$patterns[] = &#39;/width:([0-9]+)/&#39;;

$replacements[] = &#39;width=&#34;&#39;.$w.&#39;&#34;&#39;;
$replacements[] = &#39;width:&#39;.$w;
}

if( !empty($h) )
{
$patterns[] = &#39;/height=&#34;([0-9]+)&#34;/&#39;;
$patterns[] = &#39;/height:([0-9]+)/&#39;;

$replacements[] = &#39;height=&#34;&#39;.$h.&#39;&#34;&#39;;
$replacements[] = &#39;height:&#39;.$h;
}

return preg_replace($patterns, $replacements, $markup);
}</code></pre>
<p>Having this code activated by putting it in functions.php, we can use it as explained in Vinod's post (link above).</p>
<p>We want to use this function to change width and height attributes throughout the oembed code we retrieved before from the WordPress database.<br />
As explained here: <a href="http://forum.go41.de/topic/get-the-oembed-code-of-a-video-in-a-wp-29-post-from-postmeta" rel="nofollow">http://forum.go41.de/topic/get-the-oembed-code-of-a-video-in-a-wp-29-post-from-postmeta</a> 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.<br />
To do this we put into the loop this code:<br />
<pre><code>&#60;?php if(function_exists(&#39;resizeMarkup&#39;)) {
	$resizedvideo = resizeMarkup(($embedhtml), array(
	&#39;width&#39;=&#62;300,
	&#39;height&#39;=&#62;250 ));
	echo $resizedvideo; } ?&#62;</code></pre>
<p>Any questions? Sign up and ask, you are welcome.
</p>]]></description>
					</item>

	</channel>
</rss>

