Code, Tips

WordPress YouTube tip

There’s a weird issue with WordPress that means embedding YouTube video using the <object> tag (which is the standards-compliant method) causes HTML output errors.

The solution is quite simple (for anyone that’s comfortable with a little PHP) – it requires a very small update to the wp-includes/formatting.php file. In the wpautop function, there is a line that starts with $allblocks = '(?:table|thead| (it’s line 66 in the file that ships with WordPress 2.3.2).

The fix requires updating the line to begin with $allblocks = '(?:object|table|thead|.

A simple fix, but frustrating if you don’t know where to look. I’m not sure why this hasn’t been fixed in the WordPress code-base, but hopefully this simple patch will help if you’re experiencing this problem.

And don’t forget – you’ll have to apply this patch each time you upgrade WordPress.