WordPress inserts <p></p> next to shortcode return value

I have created the following shortcode code:

<?php

function box_handle($atts, $content='')
{
    extract(
    shortcode_atts(array(
                        'size' => 'narrow'), $atts));
    return '<div class="box '.$size.'">'.$content.'</div>';
}

add_shortcode('box', 'box_handle');

?>

And this:

Read More
[box]<h2>Title</h2>
Content
Content
Content[/box]

Gives me

<div class="box narrow"><br>
<h2>Title</h2>
<p>Impingement<br>
Content<br>
Content<br>
Content</p></div>
<p></p>

The problem here being the extra <br> at the top, after the opening tag. Keep reading and you will find a second error, the unwarranted <p></p>… How can I fix this? Naturally, I have gone through the HTML code in the admin panel and tried to weed out any new lines and other things around the markup which may cause this but I have not been able to fix it.

Related posts

Leave a Reply

1 comment