I know this must have been asked a hundred times but I've been trying out a number of solutions I could find but none seem to work.
I have a shortcode that wraps content:
[important_note]Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nam vel velit at ex congue aliquet.[/important_note]
I'm using the following shortcode function in functions.php:
function important_note( $atts, $content = null ) {
return '<div class="imp-note">'.$content.'</div>';
}
add_shortcode("important_note", "important_note");
This is the resulting html code:
<div class="imp-note">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<p></p>
<p>Nam vel velit at ex congue aliquet.</p>
</div>
The main issue is the empty <p> which I've been trying to solve using these solutions mentioned here: remove empty <p> tags from wordpress shortcodes via a php functon and on Github however this seems to solve <p> wrapping the shortcode not the content of the shortcode.
Having the first line without any <p> wrapping is a bit odd as well which makes me thinking that I should add code to the shortcode function?
Thanks in advance for any help.
UPDATE
Ok so this bit of code looks like it does the trick:
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
add_filter( 'the_content', 'shortcode_unautop',100 );
As seen here: https://stackoverflow.com/a/21460343/1275525 and here: http://www.paulund.co.uk/remove-line-breaks-in-shortcodes (Removing wpautop() To Content Only In Shortcodes)
AND the content in the shortcode must be like this not as I've shown above:
[important_note]
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nam vel velit at ex congue aliquet.
[/important_note]
Content is separate from the shortcode tags. That shortcode outputts the following html:
<div class="imp-note">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Nam vel velit at ex congue aliquet.</p>
</div>
Will confirm if it works on all shortcodes...