【问题标题】:Wordpress custom taxonomy term description html tagsWordpress 自定义分类术语描述 html 标签
【发布时间】:2017-01-07 16:01:42
【问题描述】:

我查看了所有堆栈溢出和 WP 论坛,但在过去几年中找不到任何适用于此问题的内容。

我为自定义帖子类型(专辑)创建了一个自定义分类(专辑类别),我需要将分类描述显示为 html 段落,但它只是输出为原始文本(这是它保存在数据库 - 根本没有 html 标签)。

我已经尝试将remove_filter( 'term_description', 'wp_kses_data' ); 添加到函数文件中,但即使在重新激活主题并更新描述之后也没有任何作用。

我可以在分类中添加一个自定义字段,但如果我可以让它使用 html 标记,那么使用现有的描述字段会很好。

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    我什至没有资格成为新手,但我确实在网上找到了以下内容,而且它似乎有效,到目前为止还没有让我的网站崩溃。不作任何暗示或其他保证。鉴于该网站对我的所有帮助,我只是觉得我应该做出贡献。

    remove_filter( 'pre_term_description', 'wp_filter_kses' );
    remove_filter( 'pre_link_description', 'wp_filter_kses' );
    remove_filter( 'pre_link_notes', 'wp_filter_kses' );
    remove_filter( 'term_description', 'wp_kses_data' );
    

    我还认为分类描述通常是一个未充分利用的功能,并且任何可用的 hack 都可能有朝一日成为功能。我期待着投票!

    【讨论】:

    • 直接复制/粘贴到我的主题,它似乎按预期工作; WordPress 现在允许我将 html 保存到字段中。
    【解决方案2】:

    使用 strip_tags() 删除 html 标签

    functions.php

    function my_custom_single_title() {
        if ( is_tax( array( 'product_cat', 'product_tag' ) ) && 0 === absint( get_query_var( 'paged' ) ) ) {
            $description = wc_format_content( term_description() );
            if ( $description ) {
                echo '<h1>' . strip_tags($description) . '</h1>';
            }
        }
    }
    remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
    add_action( 'woocommerce_archive_description', 'my_custom_single_title', 10 );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-21
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-16
      • 2012-07-11
      相关资源
      最近更新 更多