New: iPhone/iPad development course in Belgium in August.

29 May 2006

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>

Add Your Comment

Spam Protection by WP-SpamFree

Embedding SWF files into WordPress posts with SWFObject

  1. 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!

    Brajeshwar
  2. 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

    Bryan Rieger
  3. 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

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

    aral
  5. 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

    Julian Sander
  6. 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

    unijimpe
  7. [...] I recently started this blog, and in the proccess needed to find a good plugin to address the swf embedding issue. I had helped write the cakeamfphp helper for cake (a MVC php application framework), so I am aware of some of the ‘longwindedness’ of writing such a wrapper. So I went searching and found a tastey plugin from Michael Bester which I like very much. I did do a touch of tweeking as I was having issues with the WYSIWYG editor, but I explained that in a comment on Aral’s blog . [...]

    blog.abstractfactory.de » Blog Archive » SWF Object in WordPress
  8. [...] Embedding SWF files into WordPress posts with SWFObject – няколко думички и пример за използването на SWF обекта [...]

    убождане » Blog Archive » Flash Embed
  9. “Share Your Smile” » How to embed SWF Files into WordPress
  10. 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.

    Jesse
  11. [...] My method-of-choice to embed has to be SWFObject. It’s able to not only take care of what it needs to, but also integrates with several other techniques including SWFAddress. Another thing I like about it is the ability to work well within Wordpress. At first I had to fall back on some embed techniques and plugins, but after reading this post about using multiline comments, I am up and running with SWFObject again. [...]

    JUST GOOD DESIGN | BLOG » Embedding Flash
  12. 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

    Pete
  13. Thanks for the link, Pete.

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

    jay
  15. 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.

    Aral
  16. Thanks for the code.

    Srinivas
  17. I have used the Kimili Flash Plugin to Embed the Free Rider 2 Flash game on iwebie and it works great for me..

    Check out the Example

    http://www.iwebie.com/free-rider-2

    iwebie
  18. I thin this might be what your looking for

    http://wordpress.org/extend/plugins/wordpress-video-plugin/

    Tingo
  19. Pretty interesting project!

    Iscar
  20. There’s a lot of data on this site and I’ve detected some concerning people to comply. You did a nice job. Thanks!

    Sandip Saini
  21. its not working

    vinod_danims
  22. Thanks Julian!

    Konya Nakliyat
  23. can not use swfobject!!
    does any body can help me?
    i did everything, but it dos´nt work!
    do i have to edit my css? thank a lot for every one!!

    sanvaz
  24. I have copy above code to post in wordpress. but it is show only Text. I have not see the flash embed show in my post.

    sokkhim
  25. hello, i have a question, hope you can answer, how can i put my header (.swf) in my header in wordpress?

    reference
    From: http://www.cliumfibre.com/ (header)
    To: http://cliumfibre.com/news/

    hope you can help me. thanks in advance.

    -nap
    napnappon_an@yahoo.co.nz

    Nap
  26. Wow, I`m gonna be needing this.

    Thank you very very much. I have the same problem here however. :)

    Nironjin