Embedding iFrames Within WordPress Without A Plugin

However great a blogging platform WordPress may be, it certainly has one downfall that many users have picked up on – the lack of support for embedding iFrame content within WordPress posts and pages. The reason for this? Security. As always! Rejoice though! There is a workaround and in this tutorial I will guide you through creating your own WordPress shortcode to display iFrames within WordPress publications!

By simply utilising the WordPress Shortcode API, we are able to implement the following function within 0ur themes’ functions.php file…

function iframe_shortcode($atts, $content=null) { 
 extract(shortcode_atts(array( 
 'url' => '', 
 'scrolling' => 'no', 
 'width' => '400', 
 'height' => '300', 
 'frameborder' => '0', 
 'marginheight' => '0', ), 
 $atts));
 
 if (empty($url)) 
 return 'http://'; return ''; } 
 
 add_shortcode('iframe','iframe_shortcode');

By changing the following attributes in the above code:

extract(shortcode_atts(array(
'url'   => '',
'scrolling'     => 'no',
'width'     => '500',
'height'    => '400',
'frameborder'   => '0',
'marginheight'  => '0',
), $atts));

You will be able to specify default values whenever an attribute is left out of the following code which will be placed in your posts or pages within WordPress wherever you want them to appear:

[iframe url="http://www.mytutorialz.wordpress.com/" width="400" height="300" scrolling="no" frameborder="0" marginheight="0"]

A very quick and basic tip, but one that will hopefully solve a frustrating problem for many WordPress bloggers out there!

About these ads

5 responses on “Embedding iFrames Within WordPress Without A Plugin

  1. I understand how you can do this on a self-hosted wordpress blog, but how can you edit the theme functions php file on a wordpress.COM blog? That’s where this would be useful because you can use iFrames on self-hosted wordpress blogs anyway. You can’t use them on wordpress.COM blogs, and that’s where this work-around would be necessary.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s