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>

16 Responses to “Embedding SWF files into WordPress posts with SWFObject”


  1. 1 Brajeshwar

    I use my own PHP swf embedder which dynamically writes the SWFObject (FlashObject) into my blog post (works for MT and WP). So, in future if we need to change from SWFOject to something else, I just change that one single script and things will be afresh. I follow the same for all image embeds on my blog articles!

  2. 2 Bryan Rieger

    Check out the Kimli Flash Embed plug-in for WordPress - makes embedding SWF much, much easier and it’s built upon Geoff Stearn’s Flash Object javascript code.

    http://www.kimili.com/plugins/kml_flashembed

  3. 3 Julian Sander

    Hi Aral,
    after dealing with this issue myself I found the solution to fixing the plugin.. When WYSIWYG is used, it (as you mentioned) converts ” into html entities, so the solution is to convert back from html entities. :)
    add the following line to the kml_flashemed.php at line 235 inside the function kml_parse_kfe_tags($match)

    $elements = html_entity_decode($elements);

    workes like a charm now.

    Cheers, Julian

  4. 4 aral

    Thanks Julian! I’ve actually switched to using the non-WYSIWYG editor and it’s so much better so I’m happy now! :)

  5. 5 Julian Sander

    Hi Aral,

    yeah, I beleave that!! WYSI(not)WYG haha. I sent an email to Michael about this, so I hope he will include this change in the next release.

    Anyhow, I hope to be able to make it to the Flash on the Beach in December. If so we should get together for a drink. :)

    Cheers, Julian

  6. 6 unijimpe

    Hello, my name is Jim and i have created plugin for WordPress
    that it allows to insert SWFs in your WodrPress Blog. This Plugin
    this plugin uses the SWFObject library. The use is very simple, this plugin
    simply encloses the Javascript and insert code for insert SWFObject.

    The form to insert SWF is:
    [swf] pathtofile.swf, width, height[/swf]

    You can see an explanation and example in: http://unijimpe.pandela.net/?p=18

  7. 7 Jesse

    This is great, thank-you!

    The benefit to doing it this way over alternate plug-ins is the increase in functionality. Case in point, allowFullscreen = true needed for Fullscreen with Flash 9.

  8. 8 Pete

    I would really recommend Michael Bester’s excellent http://www.kimili.com/plugins/kml_flashembed

    It is lacking allowFullScreen which he’s soon to add. If you beat him to it just add

    $out[] = ‘ so_’ . $rand . ‘.addParam(”allowFullScreen”, “true”);’;

    at line 193, to have fullscreen always allowed

  9. 9 Aral

    Thanks for the link, Pete.

  10. 10 jay

    i have a problem how can get html dynamic text value into flash

  11. 11 Aral

    Hi Jay,

    You would use FlashVars to do that. In SWFObject, you use so.addVariable(”variable name”, “variable value”). See the SWFObject page for more information on how to do that.

  12. 12 Srinivas

    Thanks for the code.

  1. 1 blog.abstractfactory.de » Blog Archive » SWF Object in WordPress
  2. 2 убождане » Blog Archive » Flash Embed
  3. 3 “Share Your Smile” » How to embed SWF Files into WordPress
  4. 4 JUST GOOD DESIGN | BLOG » Embedding Flash

Leave a Reply






Bad Behavior has blocked 0 access attempts in the last 7 days.