在Woocommerce中,我正在使用模板文件中的自定义单一产品页面。
我添加了以下内容:
<?php
/** this adds the category description to each product page **/
global $post;
$args = array( 'taxonomy' => 'product_cat',);
$terms = wp_get_post_terms($post->ID,'product_cat', $args);
$count = count( $terms );
if ( $count > 0 ) {
foreach ( $terms as $term ) {
echo '<div id="cat_description_info">';
echo $term->description;
echo '</div>';
}
}
?>
它很好地添加了类别描述,但是我想在WooCommerce产品类别描述中使用[shortcode]
。我已经在子主题功能文件中尝试过:
add_filter( 'term_description', 'do_shortcode' );
add_filter( 'category_description', 'do_shortcode' );
add_filter( 'post_tag_description', 'do_shortcode' );
add_filter( 'category_description', function( $content ) {
return apply_filters( 'the_content', $content );
});
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );
//add_filter( 'term_description', 'do_shortcode' );
//add_filter( 'category_description', 'do_shortcode' );
//add_filter( 'post_tag_description', 'do_shortcode' );
//Add shortcodes in Category, Tag, and Taxonomy Descriptions
//add_filter( 'term_description', 'shortcode_unautop');
//add_filter( 'term_description', 'do_shortcode' );
add_filter( 'product_cat', 'shortcode_unautop' );
add_filter( 'product_cat', 'do_shortcode' );
//remove_filter( 'pre_term_description', 'wp_filter_kses' );
显然不是同时所有,都尝试了各种插件,但都无济于事。通常,SOF会提供我的答案,但是我很困惑,或者答案在这里,我只是错过了。
我的环境:WordPress 4.9.9,WooCommerce 3.5.1和Divi Theme 3.17.6