WordPress can do a lot to streamline your workflow, but every now and then it’ll throw a little roadblock in your path. For instance, if you’re trying to embed a video from YouTube or add Amazon’s Affiliate Marketing advertisements to your site, both of which use iFrames, you will soon find that they mysteriously disappear every time you switch from HTML to Visual mode in the editor. Needless to say, this can be very frustrating.
An iFrame is a snippet of code that allows you to embed one website inside another website. Lots of sites (Google AdSense, Amazon, YouTube, Facebook, etc.) use this to share content, and it can be tremendously useful. On the other hand, it can also be very dangerous. Since you are embedding a third-party site, you have absolutely no control over the content of that site. If that site puts up something dangerous, it’s going to display on your website. You should only use iFrame for website you trust completely.
While you can work around this issue using a plugin, there’s a simpler option available to you. Simply place the below code in your “functions.php” file before the ?> at the end of the file. You can edit this file by browsing to Appearance > Editor, and then selecting “functions.php” from the list of templates on the right. Alternatively, you could edit functions.php directly in your theme’s directory.
add_filter('tiny_mce_before_init', create_function( '$a',
'$a["extended_valid_elements"] = "iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]"; return $a;') );
That’s it! You can now embed iFrames into your WordPress posts. Just be sure to only embed them from sites you trust.