【问题标题】:Woocommerce allow html in short description on category pageWoocommerce 允许在类别页面上使用 html 进行简短描述
【发布时间】:2017-06-04 23:29:41
【问题描述】:

我正在类别页面上添加产品的简短描述(摘录),但我无法让摘录中的 html 标记正常工作。奇怪的是,它们在单一产品页面中工作。下面给出的是我正在使用的功能,以防万一。我正在为 wordpress 使用understrap 主题框架。

function woocommerce_after_shop_loop_item_title_short_description() {
    global $product;
    if ( ! $product->post->post_excerpt ) return;
    ?>
    <div itemprop="description">
        <?php echo apply_filters( 'woocommerce_short_description', $product->post->post_excerpt ) ?>
    </div>
    <?php
}
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_after_shop_loop_item_title_short_description', 5);

这是我得到的输出:

<p>lorem lipsum losem</p>

这是我想要的输出(这是我在 woocommerce 产品后端的简短描述框中添加的内容):

<ul>
    <li> lorem </li>
    <li> lipsum </li>
    <li> losem </li>
</ul>

【问题讨论】:

  • 生成的 HTML 是什么样的?期望的输出是什么?

标签: php wordpress woocommerce


【解决方案1】:
foreach ( array( 'pre_term_description' ) as $filter ) {
    remove_filter( $filter, 'wp_filter_kses' );
}

foreach ( array( 'term_description' ) as $filter ) {
    remove_filter( $filter, 'wp_kses_data' );
}

尝试将此 sn-p 添加到活动子主题的 functions.php 中

【讨论】:

    猜你喜欢
    • 2016-07-10
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 2021-02-12
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    相关资源
    最近更新 更多