[Plugin: Embed Iframe] Adding capability to apply an ID to iframe
-
I needed to apply an ID to my iframe and the shortcode this plugin uses doesn’t include this capability.
I modified version 1.0 of this plugin to include this ability. So you can use [iframe URL WIDTH HEIGHT ID]. Be aware this is hacked together and hasn’t been tested if you exclude any of the variables so including all 3 is highly recommended (although it does work if you leave off the ID).
1. Modify embediframe.php (lines 35 – 50) so it catches the 3rd variable (id)
Original:// Because the regex is such a nuisance $url = substr ($matches[1], 0, $tmp); $rest = substr ($matches[1], strlen ($url)); $width = 400; $height = 500; $parts = array_values (array_filter (explode (' ', $rest))); $width = $parts[0]; unset ($parts[0]); $height = implode (' ', $parts); return $this->capture ('iframe', array ('url' => $url, 'width' => $width, 'height' => $height));
Replacement:
// Because the regex is such a nuisance $url = substr ($matches[1], 0, $tmp); $rest = substr ($matches[1], strlen ($url)); $width = 400; $height = 500; $id = ''; $parts = array_values (array_filter (explode (' ', $rest))); $width = $parts[0]; $id = $parts[2]; unset ($parts[0],$parts[2]); $height = implode (' ', $parts); return $this->capture ('iframe', array ('url' => $url, 'width' => $width, 'height' => $height, 'id' => $id));
2. Modify view/embediframe/iframe.php to include the ID in the actual HTML that’s added to the page.
Original:<div class="iframe-wrapper"> <iframe src="<?php echo $url ?>" frameborder="0" style="height:<?=$height?>px;width:<?=$width?>px;" id="<?=$id?>">Please upgrade your browser</iframe> </div>
Replacement:
<div class="iframe-wrapper"> <iframe src="<?php echo $url ?>" frameborder="0" style="height:<?=$height?>px;width:<?=$width?>px;"<?php if($id != ''){echo' id="'.$id.'"';} ?>>Please upgrade your browser</iframe> </div>
Let me know if you have any recommended changes on my code. Or if you have a way of contacting the author to make this an official plugin feature.
- The topic ‘[Plugin: Embed Iframe] Adding capability to apply an ID to iframe’ is closed to new replies.