How to force wp excerpt to use br tag?


wp editor was replacing br tag with p tag. not all the solutions here worked. It was causing problem with design. So i disabled wpautop with below code….

remove_filter( 'the_content', 'wpautop' );

Forgot to mentioned that excerpt disappears if used….

remove_filter( 'the_excerpt', 'wpautop' );

However, the problem still persist for excerpt. In excerpt adding single br works but two br becomes p

In order to style p of excerpt i am using below filter…

add_filter( "the_excerpt", "add_class_to_excerpt" );
function add_class_to_excerpt( $excerpt ) {
return str_replace('<p', '<p class="short-desc" style="text-align: justify;"', $excerpt);

At present output is as below….

<p class="short-desc" style="text-align: justify;">text here</p>
<p class="short-desc" style="text-align: justify;">text here</p>

And i want output like below….

<p class="short-desc" style="text-align: justify;">text here<br><br/>
text here</p>

How to force wp excerpt to use br tag? or how to stop wp from making two br into p tag?

, , NehaAgra 6 years 2016-09-30T02:11:42-05:00 0 Answers 105 views 0

Leave an answer