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!
great post
Thank you very much!
Does this work for wordpress.com sites? If yes, where should i put this code?
Was wondering if I could get some help with this?
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.