Top

How to Remove Crazy WordPress MU HTML Filter

December 22, 2007

Have you ever seek for help on how to:

  • enable JavaScript for WordPress MU post;
  • remove WordPress MU HTML filter; or
  • enable advanced HTML tags and attributes, like embedded object, flash, video, etc?

I did. After migrating from WordPress 2.3.1 to WordPress MU 1.3.1 I lost all the JavaScript code from my posts and pages. I also experience few very serious issues, which I will write about later on.

The Search

I've tried to search for solution for few times. I found this post A look at WordPress filters. Disable wpautop() on post formatting. by Leonid Mamchenkov. It was not a correct solution for this problem. That post only point out how to disable the automatic insertion of <p> (paragraph tag), not enableing javascript and advanced HTML tag and styling.

Finally I found a a quick and easy solution to solve the issue. The credit goes to Robert Mao, who wrote Get rid of boring WPMU’s post html/javascript filtering…, which pointed directly at the problem and give the solution. I follow what Robert said and found that the information on "how to use Javascript" from WordPress Codex is really misleading. It is complicated and is not a solution for this problem.

The Solution

What Robert pointed out, I found valid. You can do this too, here is how you can remove the crazy WordPress MU filter for post to enable JavaScript and advanced HTML:

  1. Open file wp-includes/kse.php in your WordPress MU folder
  2. Locate line 717 to find:
    add_filter('content_save_pre', 'wp_filter_post_kses');
  3. insert # before add_filter and you should have this:
    #add_filter('content_save_pre', 'wp_filter_post_kses');

Upload the file and replace the official WordPress MU wp-includes/kse.php file.

You may want to edit the file directly on your host, it's all up to you. You may also want to make a plug in to disable the remove the filter.

What's next?

I tried to create a filter similar to what his suggested but it didn't work. This is the code I used in the filter:

remove_filter('content_save_pre', 'wp_filter_post_kses');

How about you? If you are a WordPress expert coder will you make a plugin to disable some annoying filters? If yes please give me a ping back or a comment to let me know.

Update 05/04/2009: I made the plugin, here is the link to the download page: Less Filter Plugin for Wordpress

Tags: Google Adsense, how-to, wordpress mu

Related posts

Comments

30 Responses to “How to Remove Crazy WordPress MU HTML Filter”

  1. turtie on December 23rd, 2007 4:18 pm

    This website looks like a great resource. I'm adding it to my reader!

  2. Binh Nguyen on December 26th, 2007 12:27 am

    turtie » Thanks. Your website is very nice too, but I don't know much about MatLab.

  3. Jim W on February 3rd, 2008 5:59 am

    WP internally uses the KSES PHP script (developed outside WP) to sanitize user input (to strip certain HTML tags, remove XSS, etc.). However, KSES has many bugs and lacks many features, and though it has 'evolved' into the much better htmLawed, WP doesn't use the new code. But htmLawed seems to be easily integrable in WP, and some WP-admins may want to give it a try for its extended features.

  4. Otto on March 4th, 2008 11:52 pm

    Try this in a plugin.


    function disable_kses_content() {
    remove_filter('content_save_pre', 'wp_filter_post_kses');
    }
    add_action('init','disable_kses_content',20);

  5. Binh Nguyen on March 5th, 2008 1:34 am

    Otto » Thanks. It worked and hence I will make a simple plugin to help other WMPU admins.

  6. Tim Stoop on April 8th, 2008 9:29 pm

    Hi there,

    Did you ever write that plugin? I would really be interested in it!

  7. Binh Nguyen on April 9th, 2008 2:49 am

    Tim Stoop » I did write that plugin. But I'm using it only for myself and didn't make any distribution version. I will post it on later on if you like. Do you mind wait for a few more days?

  8. Tim Stoop on April 11th, 2008 2:41 pm

    Not at all, take your time, I actually did the oneline-fix atm, but would like the plugin for a more permanent solution without the need to apply the fix each time after an update ;-) Thanks man!

  9. Tim Stoop on April 15th, 2008 10:23 pm

    For your information, today we installed this, which solved our problem: http://wpmudev.org/project/Allow-Embedded-Videos

  10. dennis on June 19th, 2008 1:26 am

    I am not a programmer but was able to add a new kses.php file, but still not able to use javascript in the post. I am wondering if you will be releasing the plugin you made. Thanks for the help,

  11. Binh Nguyen on June 21st, 2008 1:09 am

    @dennis: Thanks for reminding me of releasing this plugin.

  12. kedmond on August 14th, 2008 12:24 am

    You're awesome. I finally got this to work. I followed this procedure:

    1. Open file wp-includes/kse.php in your WordPress MU folder
    2. Locate line 717 to find: add_filter('content_save_pre', 'wp_filter_post_kses');
    3. insert # before add_filter and you should have this: #add_filter('content_save_pre', 'wp_filter_post_kses');

    However, in the current WP MU distribution, version 2.6, the line that you must edit in kses.php is Line 1021. But the command that you have to comment out is the very same as before. Thanks again!

  13. Tony on August 22nd, 2008 12:25 pm

    Thanks so much for this. I was pulling my hair out trying to get it to work.

  14. Unfilter MU’s Filters | Page 2 on October 8th, 2008 11:02 am

    [...] and Flash embeds. This would be fine if it were configurable, but sadly it is not. Various hacks exist to remedy the situation, but for such a pluggable piece of software as WordPress - hacks just [...]

  15. Html Metatags on November 24th, 2008 9:55 pm

    Wow - hot! Just what I was looking for ;-)
    Thanks!

  16. Spedman975 on December 2nd, 2008 8:35 am

    Thank GOD for you! I have been trying to figure that out for AGES... So happy now...

  17. Remove WordPress MU HTML Filter - Administration Office on January 22nd, 2009 8:05 am

    [...] from Binh.name :Filter, Html, WordPress Mu No comments for this entry [...]

  18. Lars on March 29th, 2009 8:53 pm

    Hi,

    is there any possibility to make php running in Wpmu?

  19. Binh Nguyen on March 31st, 2009 12:47 am

    You may want to try Wordpress PHP Exec Plugin for that purpose.

  20. Blok on April 1st, 2009 12:24 am

    This solves the problem but I really hate hacking the core since with every update we'll have to re-edit the file. Did you ever get around to releasing that plugin? I tried to create a plugin based on Otto's code but I couldn't get it to work - but my plugin creation ability is not where I'd like it to be.

    Thanks!

  21. Binh Nguyen on April 5th, 2009 6:36 am

    I made the plugin, here is the link to the download page: Less Filter Plugin for Wordpress

  22. Jacob on June 24th, 2009 2:15 am

    I love you! Been trying to write a plugin to unhook this for 2 days now.. This way is MUCH easier!

    I hope WP admin in future has an option to turn ON/OFF this !

    Cheers,
    Jacob

  23. Binh Nguyen on June 25th, 2009 2:55 am

    @Jacob, thanks for appreciating. I did make a plugin to unhook it. Didn't actually put on Wordpress plugins directory because no time :) But my plugin is suggested having a misspelled word and I didn't even fixed it yet :) ) so lazy I am.

  24. Billi on July 24th, 2009 3:27 am

    I was hoping I could modify this plugin to activate HTML in WordPress MU Bios (on profile pages). But, no dice.

    However, this plugin somehow worked for getting HTML into the bios:

    http://www.ternstyle.us/products/plugins/wordpress/wordpress-rich-text-biography

    It takes an interesting approach...

  25. Andy on July 31st, 2009 12:17 am

    Great info! I've been searching for a way to insert javascript and php into MU posts for hours. Thanks to you I'm finally achieving what I wanted to accomplish.

  26. DJTwittr on August 11th, 2009 5:18 am

    Hello, thanks for this tutorial. It has beendriving me crazy I was thinking a plugin blew up my html. But I would like to add that as of the 2.8.3 fork of WPMU the line number is now #1098

  27. Supun Budhajeewa on August 24th, 2009 7:36 pm

    Thanks for the tip ! That solved my problem.

  28. Hikari on January 11th, 2010 8:27 pm

    Hello. IDK if it's the same for WP MU, but in WP, the damned function that strips our text is wp_filter_kses().

    kses_init_filters() adds it as filter to 5 hooks, kses_init() calls this function, and it is added as action to init and set_current_user. All those functions are in kses.php

    Note the current_user_can('unfiltered_html'). That's the trick, kses_init() removes the filter from all hooks and adds it back if user can't use clean HTML.

    So, instead of hacking Wordpress core or using codes to remove the filter, just set unfiltered_html role to uses that should have it, and Wordpress core will do it's job nicefully without having to be hacked :D

  29. B on February 26th, 2010 4:19 am

    After three hours of searching I found this! LIFE SAVER!!!

    Thanks

  30. leomartin6 on May 19th, 2010 1:33 pm

    This solves the problem but I really hate hacking the core since with every update we'll have to re-edit the file. Did you ever get around to releasing that plugin? I tried to create a plugin based on Otto's code but I couldn't get it to work - but my plugin creation ability is not where I'd like it to be.
    ---------------------------
    Leo
    cwna

Got something to say?





Bottom