简体   繁体   中英

woocommerce product excerpt description (short)

I want to remove wordpress html-formatting in woocommerce product short description. It add p tag everywhere. I know how to do it in wp posts and pages

remove_filter( 'the_excerpt', 'wpautop' );

but it didn't work with woocommerce product short desc

i was trying to use this code

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.

  2. pass second parameter true if you want to remove break tag <br/> also.

    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. While you can call add_action() directly in your plugin/theme you cannot call remove_action() . You can see that the wpauto is added to the woocommerce_short_description filter. 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.

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. Enjoy!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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