Support » Fixing WordPress » Importing MT entries with embedded javascript

  • I’m trying to import a Movabletype 3.x export into WordPress 2. All of my Movabletype entries contain javascript that runs my photo galleries.

    After the import, WordPress shows the script source itself rather than treating the imported script as raw HTML/script text.

    It appears that WordPress is actually stripping out the <script> and </script> tags during the import process. Is there any way to tell WordPress to “leave the imported script tags alone during the import process?”


Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m having this issue as well. And importing six years worth of posts from two blogs makes me not look forward to the possiblity i’ll have to transfer the javascript by hand.

    I’ve also noticed that it’s stripping out any <style> tags as well.

    Well, i’ve been researching this and digging through the WP codebase, and it would appear that no one is responding because “it’s such a simple fix.” Of course, it’s only simple for those who already know how to do it, and it doesn’t seem to be well documented, and certainly isn’t easy to find if it is.

    Effectively, what I’ve figured out is that:
    1) You’ll have to implement this in your my-hacks.php file, which:
    1a) is being deprecated in hopes more people will make necessary plugins
    1b) you’ll have to create on your own and upload to your wordpress install directory
    1c) you have to activate in the Options -> Miscellaneous tab of your admin interface.

    2) there are two arrays built deep within the bowels of the wp code (wp-includes/kses.php specifically) called $allowedposttags and $allowedtags. you need to redefine these, and set the CUSTOM_TAGS constant to true in your my-hacks.php file

    3) open wp-includes/kses.php and copy lines 21 to 43

    4) paste those lines into your my-hacks.php file

    5) copy line 17 from kses.php into my-hacks.php as well, placing it at the end of what you copied in step 3

    6) you’ll need to add your tags into the array

    6a) to enable javascript import, copy the following:
    ‘script’ => array (‘type’ => array (),’language’ => array (),’src’ => array ())
    and paste it just before the final parenthesis-semicolon — “);” of the $allowedposttags definition

    6b) to enable (in my case) inline CSS style block import, copy the following:
    ‘style’ => array (‘type’ => array ())
    and paste it in the same location as in 6a.

    6c) when you paste these in, be sure you type in a comma in front of them, to separate them from the previous entries

    7) effectively you’re building an array of arrays: the first level represents the HTML tags, and the second level represents their attributes. I assume (but haven’t looked at the code this closely) that if the attributes don’t appear in the tag’s attribute array, that it will be stripped. in light of this, i also went through many of the tags and added “class” and “style” attributes to them, as I do occasionally use inline tag-level styles.

    8) when you’ve added all the tags and attributes you want, you need to change the CUSTOM_TAGS definition to true, as in:

    9) after you’ve done all this and saved your my-hacks.php file to your wordpress install directory, you’ll have to import your entries. Obviously, WP won’t reimport entries that already exist, so you’ll first have to delete anything you need to re-import. How you do that is a debate for another thread. Luckily I’d just gotten started when I realize that my tags were being stripped out, so i just dropped all the wp tables out of my database and ran the installer again. There’s probably an easier way to get rid of your posts, but I haven’t dug around for it.

    Hope this helps!

    i’ve also just realize this may not be enough. it’ll get the javascript in there, but if you’re using quotes (which is pretty much a given) WP is going to convert them to HTML entities and thus break your code. going to look into this as well.

    How would I modify this code to allow the use of the center tag? Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Importing MT entries with embedded javascript’ is closed to new replies.