Embedding SWF files into WordPress posts with SWFObject

I just had a heck of a time embedding a SWF file (the YouTube video from the previous post) into my WordPress post. Even when using the plain HTML editor, WordPress apparently does funny things to my HTML. Grrr! Feels like I'm using FrontPage or something!

Anyway, so I figured out that the problem was because WordPress was trying to convert the quotation marks in my code to smart quotes. Lovely! This was, of course, messing up the JavaScript required for SWFObject. So I tried putting the contents of the script tags into HTML comments, thinking WordPress might ignore the comments. And it did. But it also munged my newlines, thereby actually commenting out my JavaScript code. Grrr x 2! Finally, I got it to work by using multiline comments.

Here's the resulting code that worked:

<div align="center" id="flashCaptPicard">
    You need the Flash Player to view this video.
</div>
<script type="text/javascript">
    /*<!--*/
    var so = new SWFObject("http://www.youtube.com/v/2CTB6Lklpik", "flashCaptPicard", 425, 350, "7");
    so.write("flashCaptPicard");
    /*-->*/
</script>

Comments