wordpress snippets last updated   : August 18, 2014
we now have 638 snippets

iframe shortcode for posts and pages

wordpress snippet

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.

snippet :  PHPcopy
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>';
    }
}
snippet :  PHPcopy
[iframe url="http://wpsnipp.com" width="100" height="100" scrolling="yes" frameborder="1" marginheight="2"]

Did you like this post? If so please share it with your friends. Thanks!

  • http://harcho.com Surkho Salamov

    Thanks! great and useful feature. 

    • http://wpsnipp.com Kevin Chard

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

  • http://twitter.com/Jtsternberg Justin

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

jqsnipp.com | we just launched jquery snippets website