Stop WordPress from Automatically Inserting Paragraph Tags

WordPress automatically wraps my custom code with unwanted

tags, misaligning the elements. Example:

<select id="hour_select_<?php echo $counter; ?>">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
</select>
<span>:</span>
<select id="minute_select_<?php echo $counter; ?>">
  <option value="00">00</option>
  <option value="15">15</option>
  <option value="30">30</option>
  <option value="45">45</option>
</select>

How can I prevent this from happening?

I encountered a similar issue in one of my projects and found a few solutions that worked well for me. In my case, wrapping the custom code inside a shortcode helped because it rendered the content exactly as I intended. Another method I used was to apply remove_filter for ‘the_content’ or ‘the_excerpt’ in my functions.php file, which prevented WordPress from inserting unwanted

tags. I had to be careful because this change affects the entire site, so I applied it only selectively where needed.

In my experience, a viable alternative was to disable the auto paragraph formatting only for specific instances instead of site-wide. I achieved this by applying a custom filter that checks for a unique marker in my content and selectively removes the wpautop filter before outputting the block, then re-enables it afterward. This method provided controlled formatting and prevented interference with the rest of the site’s content, while still allowing WordPress to manage paragraphs for standard posts and pages.