php - p tag formatting in shortcode's content wordpress -
i know must have been asked hundred times i've been trying out number of solutions find none seem work.
i have shortcode
wraps content:
[important_note]lorem ipsum dolor sit amet, consectetur adipiscing elit. nam vel velit @ ex congue aliquet.[/important_note]
i'm using 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 resulting html code:
<div class="imp-note"> lorem ipsum dolor sit amet, consectetur adipiscing elit. <p></p> <p>nam vel velit @ ex congue aliquet.</p> </div>
the main issue empty <p>
i've been trying solve using these solutions mentioned here: remove empty <p> tags wordpress shortcodes via php functon , on github seems solve <p>
wrapping shortcode
not content of shortcode
.
having first line without <p>
wrapping bit odd makes me thinking should add code shortcode function?
thanks in advance help.
update
ok bit of code looks 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 , here: http://www.paulund.co.uk/remove-line-breaks-in-shortcodes (removing wpautop() content in shortcodes)
and content in shortcode must not i've shown above:
[important_note] lorem ipsum dolor sit amet, consectetur adipiscing elit. nam vel velit @ ex congue aliquet. [/important_note]
content separate shortcode tags. shortcode outputts following html:
<div class="imp-note"> <p>lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> <p>nam vel velit @ ex congue aliquet.</p> </div>
will confirm if works on shortcodes...
as i've mentioned in question's update bit of code in functions.php
trick:
remove_filter( 'the_content', 'wpautop' ); add_filter( 'the_content', 'wpautop' , 99); add_filter( 'the_content', 'shortcode_unautop',100 );
as seen in question's answer: https://stackoverflow.com/a/21460343/1275525 , post: http://www.paulund.co.uk/remove-line-breaks-in-shortcodes (scroll down to: removing wpautop() content in shortcodes)
it's important have content in shortcode separate shortcode tags, otherwise first line not wrapped in <p>
tag:
[important_note] lorem ipsum dolor sit amet, consectetur adipiscing elit. nam vel velit @ ex congue aliquet. [/important_note]
html output:
<div class="imp-note"> <p>lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> <p>nam vel velit @ ex congue aliquet.</p> </div>
i've checked shortcodes throughout wordpress site , have correct formatting. helps few peeps out there :)
Comments
Post a Comment