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 herebrbr/
text here/p

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

Topic excerpt tinymce visual-editor Wordpress

Category Web


why don't you use get_the_excerpt instead. That doesn't have the paragraph marks.

You can even use your own filters. something similar.

<?php
$my_excerpt = get_the_excerpt();
if ( '' != $my_excerpt ) {
    // Some string manipulation performed
}
echo $my_excerpt; // Outputs the processed value to the page
?>

view more on the codex

https://codex.wordpress.org/Function_Reference/get_the_excerpt

There is a the difference between get_the and just the excerpt. Returning excerpt with out "get" automatically includes the echo. It also cleans the result and adds paragraph marks. If you want to manipulate before returning you need to "get" the excerpt content, manipulate, and then echo it.

So use

<?php echo get_the_excerpt(); ?>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.