Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>
share|improve this question
2  
> "Tried wp_autop thing ..." You mean something like this: remove_filter( 'the_content', 'wpautop' ); ? –  TheDeadMedic Nov 16 '12 at 17:05
    
Are you switching between Visual and HTML editors while editing posts? –  Chip Bennett Nov 19 '12 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 Nov 19 '12 at 14:22
add comment

2 Answers 2

up vote 3 down vote accepted

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 ); ?>
share|improve this answer
    
Shortcodes will not be processed and this could break quite a bit of plugin functionality. –  s_ha_dum Nov 16 '12 at 15:57
    
Yeah, that works as long you don't have plugins that uses [---] tags in editor if I'm correct? –  Philip Nov 16 '12 at 17:10
2  
There's a do_shortcode() for that... –  Chip Bennett Nov 16 '12 at 17:13
1  
Thanks for the edit, Chip! –  guiniveretoo Nov 19 '12 at 0:15
    
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 Nov 19 '12 at 9:04
show 2 more comments

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

share|improve this answer
1  
Have you ever looked up the source to check what exactly is responsible for removing the paragraphs and linebreaks? –  kaiser Nov 16 '12 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 –  Mridul Aggarwal Nov 16 '12 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. –  Chip Bennett Nov 19 '12 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" –  Mridul Aggarwal Nov 19 '12 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. –  Chip Bennett Nov 19 '12 at 13:01
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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