Allow iframe in WordPress Posts

If you’ve ever tried adding an iframe to your WordPress post, and then switched the TinyMCE editor to Visual mode, you’ve found that the editor strips out your iframe code. This can be annoying. Just add this snippet to the functions.php file in your theme folder to prevent TinyMCE from killing your iframe.

 
function add_iframe($arr) {
	$arr['extended_valid_elements'] = "iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]";
	return $arr;
}
add_filter('tiny_mce_before_init', 'add_iframe');
 
global $allowedposttags;
$allowedposttags["iframe"] = array(
        "id" => array(),
		"class" => array(),
		"title" => array(),
		"style" => array(),
		"align" => array(),
		"frameborder" => array(),
		"longdesc" => array(),
		"marginheight" => array(),
		"marginwidth" => array(),
		"name" => array(),
		"scrolling" => array(),
		"src" => array(),
        "height" => array(),
        "width" => array()
);

Share this

The Author

admin - Hello, my name is Simon, I’am 25 and I’m a software and web developer. My interests span all aspects of programming and development, including ASP, JavaScript, AJAX, PHP, .NET, Java, C#, C++, Objectv-C, Flash, Cocoa, SQL, XML and everything in between. www.simra.ch

Leave a Reply

*
 
© 2010 onYou GmbH. All Rights Reserved