0

I've been trying to make wordpress stop adding html tags to my content but leave my own html tags alone?

Tried remove_filter( 'the_content', 'wpautop' ); and installed PS Disable Auto Formatting but the problem is that it removes my own html tags aswell?

I've tried to get_the_content() and the_content() but the same problem occurs there...

The way I wan't this to work is to let me add html tags and leave these alone, not removing them. Like this:

<p>Some text here</p>
<p>some more text <span class="fat"> fat </span></p>
3
  • 2
    > "Tried wp_autop thing ..." You mean something like this: remove_filter( 'the_content', 'wpautop' ); ? Commented Nov 16, 2012 at 17:05
  • Are you switching between Visual and HTML editors while editing posts? Commented Nov 19, 2012 at 13:02
  • No I wasn't but I just tried to deactivate the visual editor and now it works, I haven't touched the visual editor and think it's rather shitty to have a tabbed option where you can switch to html, but then it doesn't work...? So your only option is to either have the visual on or off?
    – Philip
    Commented Nov 19, 2012 at 14:22

2 Answers 2

3

Try accessing the $post object inside your loop, and echo'ing the content from that. Something like:

<?php echo $post->post_content ?>

Edit

If you need to parse shortcodes, use do_shortcode():

<?php echo do_shortcode( $post->post_content ); ?>
6
  • Shortcodes will not be processed and this could break quite a bit of plugin functionality.
    – s_ha_dum
    Commented Nov 16, 2012 at 15:57
  • Yeah, that works as long you don't have plugins that uses [---] tags in editor if I'm correct?
    – Philip
    Commented Nov 16, 2012 at 17:10
  • 2
    There's a do_shortcode() for that... Commented Nov 16, 2012 at 17:13
  • I've tried this now. <?php while( have_posts() ) : the_post(); echo do_shortcode( $post->post_content ); endwhile ?> removes my <p> tags but doesn't add any new, so it's not working the way I want it to work...
    – Philip
    Commented Nov 19, 2012 at 9:04
  • I got this working after deactivating the visual editor, however I find it very confusing of having a option to use HTML in the editor when it doesn't work fully...
    – Philip
    Commented Nov 19, 2012 at 14:23
0

The only way i've ever found (& maybe also the only one that actually works)

Install & activate the plugin TinyMCE Advanced

Go to the plugin's settings page & check the box against "Stop removing <p> & <br> tags"

Go to your post's edit screen, switch between visual & html editor as often as you like & see the difference

6
  • 1
    Have you ever looked up the source to check what exactly is responsible for removing the paragraphs and linebreaks?
    – kaiser
    Commented Nov 16, 2012 at 20:44
  • nope. must be somewhere in tinymce's javascript. It happens if i type in html editor, then switch to visual editor & then come back to html editor to find they are all gone Commented Nov 16, 2012 at 21:24
  • 1
    "It happens if i type in html editor, then switch to visual editor & then come back to html editor to find they are all gone" - That's a feature, not a bug in WordPress' TinyMCE implementation. Long story, short: don't switch between Visual and HTML editors while editing posts. Pick one or the other, and stick with it. Commented Nov 19, 2012 at 12:00
  • 1
    Personally, i don't like visual editors at all. But i've seen many bug reports for this thing & most of the time the clients would stick to "I don't care how it works, i just want it fixed" Commented Nov 19, 2012 at 12:24
  • In that case, you actually want to ask a different question: How to prevent TinyMCE from stripping HTML tags when switching between HTML and Visual editors? Of course, that question has been asked and answered quite a few times. I think this answer should be what you need. Commented Nov 19, 2012 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.