Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to allow html tag when use the wp_trim_words

Tags:

trim

wordpress

I want to show some content of post in anchor tag and show as link but I have use wp_trim_words function I don't know how to allow the html tags.

$more = ' <a href="'. get_permalink( get_the_ID() ) . '" class="readMoreBtn">Read More</a>';
$content = wp_trim_words( get_the_content(), 50, $more );
echo   do_shortcode($content);
like image 438
pia Avatar asked Mar 18 '16 07:03

pia


1 Answers

Thanks to @dingo_d but he missed wpautop() in the code. Here is the updated code.

$more = ' <a href="'. get_permalink( get_the_ID() ) . '" class="readMoreBtn">Read More</a>';

echo force_balance_tags( html_entity_decode( wp_trim_words( htmlentities( wpautop(get_the_content()) ), 100, $more ) ) );
like image 51
Faisal Alvi Avatar answered Oct 13 '22 20:10

Faisal Alvi