如何去除WordPress卡片tooltip中摘要的<p>标签?
解决方法
直接用 get_the_excerpt() 配合 strip_tags() 和 trim() 函数处理,替换你的代码为:
<div class="cardpro-main" title="<?php echo trim(strip_tags(get_the_excerpt())); ?>" data-toggle="tooltip" data-placement="bottom">
各函数作用:
get_the_excerpt():获取文章摘要的原始字符串(区别于直接输出的the_excerpt(),适合用于属性赋值场景)strip_tags():彻底移除所有HTML标签,包括默认包裹摘要的<p>标签trim():清理字符串首尾的空白、换行符,让tooltip显示的内容更干净
WordPress默认会给 the_excerpt() 的输出自动添加 <p> 标签,所以改用返回字符串的 get_the_excerpt() 来处理是更合适的做法。
内容的提问来源于stack exchange,提问作者Developer
相关产品推荐
相关产品推荐

