WordPress 删除摘录过滤器

发布于 2025-01-08 03:58:22 字数 983 浏览 2 评论 0原文

我正在尝试删除默认情况下为 the_excerpt(); 放置的周围标签;

我已经尝试过以下...

<?php remove_filter('the_excerpt', 'wpautop'); ?>
<p class='test'><?php the_excerpt(); ?></p>

并且我已经尝试过...

<?php $formatted = remove_all_filters('the_excerpt', the_excerpt()); ?>
<p class='test'><?php echo $formatted ?></p>

我正在寻找生成这个...

<p class='test'>the excerpt text <a href='http://continuereadinglink'>etc.</a></p>

但是 WordPress 输出了这个...

<p class='test'></p>
<p class='default-align'>the excerpt text <a href='http://continuereadinglink'>etc.</a></p>

我实际上在这里找到了解决方法 http://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/,但它基本上涉及替换这excerpt 函数,我宁愿避免这种情况,因为我只想去掉过滤器。

I'm trying to strip the surrounding tags that are put out by default for the_excerpt();

I've tried the following...

<?php remove_filter('the_excerpt', 'wpautop'); ?>
<p class='test'><?php the_excerpt(); ?></p>

and I've tried...

<?php $formatted = remove_all_filters('the_excerpt', the_excerpt()); ?>
<p class='test'><?php echo $formatted ?></p>

I'm looking to produce this...

<p class='test'>the excerpt text <a href='http://continuereadinglink'>etc.</a></p>

But instead WordPress outputs this...

<p class='test'></p>
<p class='default-align'>the excerpt text <a href='http://continuereadinglink'>etc.</a></p>

I have actually found a workaround here http://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/, but it basically involves replacing the excerpt function, and I would rather avoid this since I just want to strip the filters out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最偏执的依靠 2025-01-15 03:58:22

HTML 段落标签不支持嵌套结构。尝试用块元素(例如 DIV
)包围摘录

您可以尝试此选项:

<p class="test"><?php echo strip_tags(get_the_excerpt()) ?></p>

HTML paragraph tags don't support nested structure. Try to surround the excerpt with block elements such as DIV

You may try this option:

<p class="test"><?php echo strip_tags(get_the_excerpt()) ?></p>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文