I know that this must have been asked a hundred times, but I tried to find many solutions that could be found, but no one works.
I have a shortcode that wraps the contents:
[important_note]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam vel velit at ex congue aliquet.[/important_note]
I use the following shortcode functions.php 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 problem is the empty <p> , which I tried to solve using the solutions mentioned here: remove empty <p> tags from Wordpress shortcodes via php functon and Github , however this seems to solve the <p> shortcode wrapping and not the shortcode content .
If the first line without any <p> wrapping is also odd, what makes me think that I should add code to the shortcode function?
Thanks in advance for your help.
UPDATE
Ok, so this bit of code looks like a trick:
remove_filter( 'the_content', 'wpautop' ); add_filter( 'the_content', 'wpautop' , 99); add_filter( 'the_content', 'shortcode_unautop',100 );
As shown here: https://stackoverflow.com> )
And the content in the short code should be as 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 shortcode tags. This shortcode outputs 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 check if it works in all shortcodes ...