I know this has been discussed to death in previous threads, but most of them are now closed. I've got a couple of outside the box fixes for this.
1) use your theme code to override the wp_autop filter, I shut it off for any content that begins with an HTML5 <section>:
function no_autop($pee) {
$text = trim($pee);
$len = strpos($text, ' ');
$text = substr($text, 0, $len);
if ('<section' == $text) {
return $pee;
}
else {
return wpautop($pee);
}
}
// disable auto-p
remove_filter('the_content', 'wpautop');
// add conditional auto-p
add_filter('the_content', 'no_autop');
I suppress the added <p></p> and
tags in some cases using jQuery and a line of css:
jQuery(function()
{
jQuery("p:empty").addClass('empty');
jQuery("img").prev("br").addClass('empty');
jQuery("section").prev("br").addClass('empty');
});
.empty {
display:none;
}
You could also just remove them in the jQuery or with a regex after the call to wp_autop in the no_autop function, it's up to you.
/peter