我想在使用wp_trim_words时允许html标记

pia*_*pia 4 wordpress trim

我想在锚标签中显示帖子的一些内容并显示为链接但我使用的wp_trim_words功能我不知道如何允许html标签.

$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);
Run Code Online (Sandbox Code Playgroud)

Fai*_*lvi 8

@dingo_d忘了在代码中添加wpautop().只需使用下面的代码.

$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 ) ) );
Run Code Online (Sandbox Code Playgroud)


din*_*o_d 4

啊啊啊我傻了。这将起作用(已测试):

$more = ' <a href="'. get_permalink( get_the_ID() ) . '" class="readMoreBtn">Read More</a>';
 echo force_balance_tags( html_entity_decode( wp_trim_words( htmlentities( get_the_content() ), 50, $more ) ) );
Run Code Online (Sandbox Code Playgroud)

我花了一段时间才想起wp_trim_words()从内容中删除了所有标签,因此您的 HTML 没有显示。所以我做了一些挖掘并发现了这个宝石:

WordPress 轨道票#29533

希望这可以帮助。抱歉之前造成的混乱:)