I notice that theres invalid markup in my shortcode. Its ok if I disable wpautop
tho
function shortcode_banner($attrs, $content = '') {
echo ' --- ' . $content . ' --- ';
$html = '<section id="banner"><div class="wrap">' . do_shortcode($content) . '</div></section>';
die($html);
}
When autop is enabled I get (notice the closing </p>
at the start?)
--- </p>
<h1>The title</h1>
xxx ... xxx ...
---
<section id="banner"><div class="wrap"></p>
<h1>The title</h1>
xxx ... xxx ...
</div></section>
When disabled I get
---
<h1>The header</h1>
xxx ... xxx ...
---
<section id="banner"><div class="wrap">
<h1>The header</h1>
xxx ... xxx ...
</div></section>
UPDATE: I notice this happens only when I have a tag (e.g. <h1>
) after my shortcode. Like:
[banner]
<h1>Test</h1>
If I have
[banner]
xxx ...
it’s ok, except WordPress adds a <br />
Try this:
I don’t know what causes this issue, but you can use the
force_balance_tags()
function to clean up the markup after the fact.Note that there are some caveats to using
force_balance_tags()
in practice.