简体   繁体   English

woocommerce 产品摘录说明(短)

[英]woocommerce product excerpt description (short)

I want to remove wordpress html-formatting in woocommerce product short description.我想在 woocommerce 产品简短描述中删除wordpress html 格式 It add p tag everywhere.它到处添加p标签。 I know how to do it in wp posts and pages我知道如何在 wp 帖子和页面中做到这一点

remove_filter( 'the_excerpt', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' );

but it didn't work with woocommerce product short desc但它不适用于 woocommerce 产品简短描述

i was trying to use this code我正在尝试使用此代码

remove_filter( 'woocommerce_single_product_summary', 'wpautop' ); remove_filter( 'woocommerce_single_product_summary', 'wpautop' );

Thank you anyway!不管怎样,谢谢你!

you can do it like this... 你可以这样

function rei_woocommerce_short_description($the_excerpt) {

    return wp_strip_all_tags($the_excerpt);
}
add_filter('woocommerce_short_description', 'rei_woocommerce_short_description',10, 1);

Note: 注意:

  1. wp_strip_all_tags will strip all HTML tags including script and style. wp_strip_all_tags将剥离所有HTML标签,包括脚本和样式。

  2. pass second parameter true if you want to remove break tag <br/> also. 如果你想删除突破标签传递的第二个参数真<br/>也。

    return wp_strip_all_tags( $the_excerpt, true );

To remove a filter you have to call that from inside a function that is added to a hook. 要删除过滤器,您必须从添加到挂钩中的函数内部调用该过滤器。 I don't 100% know why that is, but that seems to be the case. 我不是100%知道为什么会这样,但事实确实如此。 While you can call add_action() directly in your plugin/theme you cannot call remove_action() . 虽然您可以直接在插件/主题中调用add_action() ,但不能调用remove_action() You can see that the wpauto is added to the woocommerce_short_description filter. 您可以看到wpauto已添加到woocommerce_short_description过滤器中。 So to remove it you must do something like the following: 因此,要删除它,您必须执行以下操作:

function so_34700299_remote_autop(){
    remove_filter( 'woocommerce_short_description', 'wpautop' );
}
add_action( 'wp_head', 'so_34700299_remove_autop' );

I'm an minimalistic guy and try to keep my codes minimal, logical and clean as much as possible.我是一个极简主义的人,尽量让我的代码尽可能简洁、合乎逻辑和干净。 Just like you do remove 'wpautop' in post and pages content, use the same remove filter function, but with correct hook.就像您删除帖子和页面内容中的“wpautop”一样,使用相同的删除过滤器 function,但使用正确的钩子。

remove_filter('woocommerce_short_description','wpautop');

This is all you would need.这就是您所需要的。 No fanciness in the functions.php, no creating of additional functions with a hook and then calling remove filter in it. functions.php 中没有幻想,没有使用钩子创建附加函数,然后在其中调用 remove filter。 Enjoy!享受!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM