X

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.



Code Snippet:


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>';
}
}


Code Snippet:


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

Comments  Leave a Reply

  1. Facciolini Rosetta November 13, 2015 at 2:12 pm

    Great! Thanks.
    I just wish to become responsive height, or, if imposed, for example: ‘height’ => ‘300’, with a small monitor disappears a piece of content

  2. glad you like it!  shout out to @tweetsfromchris:twitter for this one, actually!

  3. Surkho Salamov July 11, 2011 at 1:24 pm

    Thanks! great and useful feature. 

    1. Cool glad you like the snippet. Shout out to Justin for this one!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!