Disable WordPress from adding <p> tags

All I’ve got is the following little snippet of code:

<select size="1" name="EventHour<?php echo $i; ?>"> 
    <option>1</option> 
    <option>2</option> 
    <option>3</option> 
    <option>4</option> 
    <option>5</option> 
    <option>6</option> 
    <option>7</option> 
    <option>8</option> 
    <option>9</option> 
    <option>10</option> 
    <option>11</option> 
    <option>12</option> 
  </select> 
  : <!-- note this character -->
  <select size="1" name="EventMinute<?php echo $i; ?>"> 
    <option>00</option> 
    <option>05</option> 
    <option>10</option> 
    <option>15</option> 
    <option>20</option> 
    <option>25</option> 
    <option>30</option> 
    <option>35</option> 
    <option>40</option> 
    <option>45</option> 
    <option>50</option> 
    <option>55</option> 
  </select> 

The should output fine. However, WordPress adds a p-tag around both of my select-elements as well as around the “:”-character. This makes them all end up on different rows.

Read More

I’ve installed and activated the WordPress plugin “Disable Visual Editor WYSIWYG” on this page without any success. Any other ideas what I can do to stop this from happening?

Related posts

Leave a Reply

10 comments

  1. You can minify your code. WordPress won’t destroy code if everything is on one line.

    I do that when I want to put <style> or <script> tags inside certain posts.

  2. In my case, I’m doing it manually for the page:

    Result that shows extra p tags:

     <p><?php if($description){ echo $description; } ?></p> 
     <p><?php if($description){ echo wpautop($description); } ?></p> 
    

    Result that removes extra p tags:

     <?php if($description){ echo wpautop($description); } ?>  
    

    Note, I removed the p tags around the echo, then added wpautop to the echo.

    End Result:

    <p>description content</p> 
    
  3. If the post is custom post type, you can add meta box with add_meta_box and there you can initialize your own editor with wp_editor which can be customized. For example you can pass settings to the tinymce like ‘force_p_newslines’ and ‘forced_root_block’

  4. At least with contact-form-7 I had some success using a html-minifier to prevent those pesky p-tags. Came here because I googled if others also find this as frustrating as I do.

    If you still have problem after code minifire then use just convert your tag to div where p tag is automatically add.

  5. if anybody else is having this problem and can’t or doesn’t want to install another plugin, or again can’t or doesn’t want to have to edit their functions.php file, you can also do this!

    My original code:

    your original code
    
    that worked wonderfully..
    
    and then wordpress happened
    

    My code with the workaround:

    your original code
    //
    that worked wonderfully..
    //
    and then wordpress happened
    

    So long as I make sure to not have any empty lines in my code this seems to be a workaround for me at least. I’m wondering if the : wasn’t enough to trick it not to add a p tag, but I’m coding in javascript and it worked for me.

  6. Another workaround:
    Put your select inside a <div> tag, without any whitespace chars between them. So Instead of :

    <select ...>
    </select>
    
    <select ...>
    </select>
     
    

    You write this:

    <div><select ...>
    </select></div>
    
    <div><select ...>
    </select></div>
    

    I’ve had the same problem with <a> elements, and this solved for me.