You could try replacing the extra <br />
at the beginning of the shortcode content.
You could achieve that in many ways, but here’s an example:
if( '<br />' === substr( ltrim( $content ), 0, 6 ) )
$content = substr( ltrim( $content ), 6 );
return '<div class="pncode">' . $content . '</div>';
where we play with the substr()
and ltrim()
functions.
Update:
Thanks to @userabuser for his comment.
If we want to remove all variations of br
tags, from the beginning of the shortcode string, we might try to construct this kind of reg-ex replacement:
$content = preg_replace( '#^\s*(<br\s*/?>\s*)+#i', '', $content );
Example:
The shortcode content:
<br /> <br>
<BR> <bR>
some sample code <br />
some sample code <br />
some sample code <br />
would display as:
some sample code <br />
some sample code <br />
some sample code <br />