iframe shortcode for posts and pages

Adding this snippet to the functions.php of your wordpress theme will add a new shortcode so that you can add an iframe in posts or pages to any URL.

 

 

add_shortcode('iframe', array('iframe_shortcode', 'shortcode'));
class iframe_shortcode {
function shortcode($atts, $content=null) {
extract(shortcode_atts(array(
'url'      => '',
'scrolling'      => 'no',
'width'      => '100%',
'height'      => '500',
'frameborder'      => '0',
'marginheight'      => '0',
), $atts));
if (empty($url)) return '<!-- Iframe: You did not enter a valid URL -->';
return '<iframe src="'.$url.'" title="" width="'.$width.'" height="'.$height.'" scrolling="'.$scrolling.'" frameborder="'.$frameborder.'" marginheight="'.$marginheight.'"><a href="'.$url.'" target="_blank">'.$url.'</a></iframe>';
}
}

 

[iframe url="http://wpsnipp.com" width="100" height="100" scrolling="yes" frameborder="1" marginheight="2"]

Leave a comment