How to stop the wp_editor from removing styles and formatting
The wp-editor is very easy to include in plugins and themes but it keeps stripping out your formatting and just doesn’t like links and media. It can however be tamed with a few simple tweaks.
Note: this isn’t a tutorial on how to use the wp-editor. The codex has all the information you need to add wp_editor to a theme or plugin. This article is just on how to get the wp-editor to behave.
The basic call to the function is:
[php][/php]$content is the bit you see when the editor loads.
$editor-id is the output. Only use lowercase characters and no underscores.
I use the wp_editor within a form and save the output to my theme/plugin options table.
If you just want plain text this will work just fine. If you want to add styles, links, media and other features it will all go pear shaped.
WordPress likes to add slashes to everything so you need to strip them out. Change your code to:
[php][/php]This will make sure that when you save your edited content everything will stay the same.
Next up is to get WordPress to display the output correctly on your site. If you just use:
[php][/php]Things will go awry. The words will appears but everything else won’t do as it is told. Styles, images, links and everything else falls over. But change it to this:
[php][/php]And all will be peachy.
The wpautop stops WordPress from removing the paragraphs
The stripslashes is needed to make sure links and media work.
That’s it. If you make sure you do the above you shouldn’t have any problems with the editor.
Thank you very much!!!
Thank You Thank You Thank You Thank You Thank You Thank You!!
Hi Chris,
Pleased it worked – it took me a long time to find this fix
Hi, there seem to be a problem with your code tags, I only see [php][/php] from my computer.
Thanks anyway !
Fixed it. I’d deactivated the plugin that allow code in posts. Doh!
Thanks for this!