Raw output (preventing wpautop)

Using WordPress 3.5.

I’m trying to put a <form> into a Page of a WP-based site. Unfortunately, WP is “helpfully” screwing up the formatting of the form by inserting <br> and <p> tags in inappropriate places next to the form controls.

Read More

I don’t want to disable wpautop globally, as it’s still helpful for blog posts (particularly as this is a multi-author site). I don’t even want to disable it for the whole of the page. I want some way to disable it only in this one specific section of this one page.

I read in the WP changelogs that supposedly shortcodes do not run wpautop on their output any more, so I tried creating the following shortcode:

function raw_shortcode( $atts, $content = null ) {
   return $content;
}
add_shortcode('raw', 'raw_shortcode');

Unfortunately this does not appear to work — surrounding the form with this still results in undesirable breaks and paragraphs being added.

I’ve seen a few examples suggesting a modification to the standard filters, but I’ve also read some other pages that suggest this is a bad idea.

Related posts

Leave a Reply

2 comments

  1. Try to modify your shortcode function to output your form – I mean insert your form html to $output varible of your code:

    function raw_shortcode( $atts ) {
        $output = '<form><label for="id">Label</label><input type="text" name="name" id="id"/></form>';
        return $output;
    }
    add_shortcode('form', 'raw_shortcode');
    

    And than just add [form] to your content.