You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何去除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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 00:25:16