Clicky

Help, advice and consultation on how to get the best out of your website

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.

  1. Ingo on 09 Mar 2018:

    Thank you very much!!!

    Reply to Ingo

  2. Chris on 04 Oct 2016:

    Thank You Thank You Thank You Thank You Thank You Thank You!!

    Reply to Chris

    • Aerin on 04 Oct 2016:

      Hi Chris,
      Pleased it worked – it took me a long time to find this fix

      Reply to Aerin

  3. Francis Bégin on 14 Aug 2016:

    Hi, there seem to be a problem with your code tags, I only see [php][/php] from my computer.

    Thanks anyway !

    Reply to Francis Bégin

    • Aerin on 14 Aug 2016:

      Fixed it. I’d deactivated the plugin that allow code in posts. Doh!

      Reply to Aerin

  4. Mayra on 08 Nov 2013:

    Thanks for this!

    Reply to Mayra

Add a comment
Your name
Your email

Are you struggling with ranking, attracting visitors, generating leads or getting sales?

Or are you just stuck not knowing what to do next?

Call me on: 01252 643927 or 07921 859802 or Send me an email.

Or fill in this form which will appear as if by magic