Woocommerce 简短描述显示 HTML

发布于 2025-01-11 22:03:39 字数 910 浏览 0 评论 0原文

我试图找出在 WordPress 中使用 Woocommerce 时如何在类别列表页面的简短描述中显示 HTML 标签。

类别列表将显示带有以下信息的产品:

Image
Product Title
Short Description
Price

这可能最终会类似于

Toy Car
This toy car has
the following benefits
it has wheels
it can turn corners fast
it is a nice red colour

事实上,因为我已启用 HTML 编辑器来进行简短描述,当您查看产品时,内容可能类似于:

<h2>Toy Car</h2>
<p>This toy car has the following benefits:</p>
<ul>
<li>it has wheels</li>
<li>it can turn corners fast</li>
<li>it is a nice red colour</li>
</ul>

问题是Woocommerce(或 Wordpress)中的某些内容正在删除 HTML 代码,因此我只留下文本。

在我的研究过程中,我遇到过提到“unfiltered_html”、“wp_strip_all_tags”和“wp_trim_excerpt”的文章(因为显然简短的描述被认为是摘录。

我希望只是一个过滤器来防止 HTML 被剥离)然而,尽管经过几个小时的搜索,我还没有找到大量关于如何实现剥离和利用它的解决方案,但没有任何解决方案可以回答我禁用它的问题。剥离功能并保留 HTML

有谁可以帮忙吗?

I am trying to find out how to display HTML tags within the short description on a category listing page when using Woocommerce in Wordpress.

The category listing will display a product with the following information:

Image
Product Title
Short Description
Price

Which may end up being something like

Toy Car
This toy car has
the following benefits
it has wheels
it can turn corners fast
it is a nice red colour

When in actual fact, because I have enabled the HTML editor for the short description when you view the product the content maybe something like:

<h2>Toy Car</h2>
<p>This toy car has the following benefits:</p>
<ul>
<li>it has wheels</li>
<li>it can turn corners fast</li>
<li>it is a nice red colour</li>
</ul>

The problem is that something in Woocommerce (or Wordpress) is stripping out the HTML code so I am just left with text.

During my research I have encountered articles which mention 'unfiltered_html', 'wp_strip_all_tags' and 'wp_trim_excerpt' (because apparently the short description is considered to the excerpt.

I was hoping it would be as easy to just a filter to prevent the stripping of HTML and yet despite hours of searching, I haven't found a solution. Plenty of solutions on how to achieve stripping and utilise it but nothing that answers my questions of disabling the strip function and retaining HTML.

Can anyone help? Please?

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

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

发布评论

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

评论(1

千柳 2025-01-18 22:03:39

同样在这里。实际上,它在我的产品页面上显示为
,但是当我使用 $product->get_short_description()$product->post 调用它时->post_excerpt 它去除 html 标签。

我设法通过搜索 woocommerce 模块文件找到了解决方案:
apply_filters( 'woocommerce_short_description', $product->get_short_description() );

Same here. Actually it shows with <br> on my product page but when I call it with $product->get_short_description() or $product->post->post_excerpt it strips html tags.

I managed to find a solution by searching inside woocommerce module files:
apply_filters( 'woocommerce_short_description', $product->get_short_description() );

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