I apologize as I realize this has been asked before and I believe the issue is with wpautop
function adding closing p or br tags but every solution I've found has not worked so I'm at a loss for fixing the issue.
I'm doing:
class my_plugin {
public static function init() {
remove_filter('the_content', 'wpautop');
add_shortcode('myshortcode', array(__CLASS__, 'my_shortcode'));
}
public static function my_shortcode() {
/* do stuff here */
ob_start();
include('views/file.php');
return ob_get_clean();
}
}
my_plugin::init();
I've also tried:
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99 );
add_filter( 'the_content', 'shortcode_unautop', 100 );
This is what's in the view file right now:
<form method="get" id="search" action="<?= get_permalink() ?>">
<input name="st" id="st" class="text" type="text">
<input id="search" class="submit" value="Search" type="submit">
</form>
And here is what's being rendered:
<form method="get" id="search" action="">
<input name="st" id="st" class="text" type="text"><br>
<input id="search" class="submit" value="Search" type="submit"><br>
</form>
If I take the original version and remove all line breaks it renders correctly. The issue is it's a significantly simplified version of original file and it would make editing "views" a nightmare if they had to be on a single line.
For what it's worth if instead of returning the view content I echo it out everything works as expected (except of course being able to place the shortcode in other content correctly).
Also the do stuff here part is just getting two variables from the request and one API call to set up the variables used in the view.
remove_filter()
code in themy_shortcode()
function?remove_all_filters( 'the_content' );