Top

How to prevent wordpress from messing up with your rich editing tags

August 30, 2008 by admin 

After spending countless hours fighting with wordpress changing my tags and text formatting in it's rich text editor I finally decided to create a tiny little cute plugin that makes wordpress to leave alone my HTML formatting, tags and line breaks. Essentially the source code of the whole thing is this:
function myautop ($text) { return $text; }
function mytext  ($text) { return $text; }
remove_filter ('the_content', 'wpautop');
add_filter    ('the_content', 'myautop');
remove_filter ('the_content', 'wptexturize');
add_filter    ('the_content', 'mytext');
You may download actual plugin from the link below. Just unzip, copy it into ./plugins directory, activate and enjoy. Note: to fix another big annoyance with Wordpress eliminating line breaks - this is what I use to "create" line breaks that Wordpress doesn't kill. In HTML mode insert this code:
<div style="margin:2em;"><span style="display:none;">-</span></div>
Advantage of this method is that you can regulate size of your "custom line break" by changing value in "margin" CSS tag. Bonus TIP: Actually I just found a better way to keep linebreaks: Advanced TinyMCE plugin seems to add lot more features to TinyMCE editor as well as has an option to stop Wordpress's messing up with line breaks.
-

Download: WP-AllowTags Wordpress Plugin that allows inserting tags

Comments

One Response to “How to prevent wordpress from messing up with your rich editing tags”

  1. John Pecheff on November 14th, 2008 12:58 am

    To help other users:

    I searched for a while how to prevent the WP editor from changing my code, how to desactivate wpautop or wptexturize, how to remove the filters, etc, until I came to this post and finally “broke the code” for me. Read on.

    So I found and tried WP-allow-tags because I just could not put in a simple script to verify a form in a post. But the plugin did not work for me, so I tried to modify it and create a new wpautop function.

    WP then just disabled the plugin as I created a fatal error, but at the same time it gave me the line of code where there was a conflict (I could have found it by searching through the installation of course).

    So I went to the wp-includes/formatting.php file and simply commented both function wpautop and wptexturize just leaving the proper return at the end. See below.

    function wpautop($pee, $br = 1) {
    /*
    … lines of code …
    */
    return $pee;
    }

    Same for wptexturize:

    function wptexturize($text) {
    /*
    … lines of code …
    return $output;
    */
    return $text;
    }

    That for sure worked for me! No more changing of my HTML or other code in posts when saving. And I did not notice any negative effects so far.

    I hope it does work for you too if you need it that way.

    Best,
    John

Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!





Bottom