2

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.

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.

1

Late to the party, but this plugin, Toggle wpautop, lets you selectively disable whether you want WP to butcher your content on pages or posts, and works on WP 4.9 (current version as of this answer).

| improve this answer | |
0

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.

| improve this answer | |
  • Yeah, I thought of that, and might even end up doing it. But it seems ugly, as it separates the form content from the context of the page where it's supposed to appear. – Miral Jan 31 '13 at 21:40
  • Any solution? I'm looking for a way to put code in articles/pages that is not modified by WP – Olivier Pons Nov 25 '13 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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