3
votes

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!

2
This might be of use to you in extremis - never a good idea to mess with core files but if you can't stop it any other way core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/… is the wp_autop() This was where a similar but dieefernt thing happened stackoverflow.com/questions/33850117/…Steve
remove_filter( 'woocommerce_single_product_summary', 'wpautop' ); add_filter( 'woocommerce_single_product_summary', 'wpautop' , 99 ); might be a more correct way to get there if it works: ipanelthemes.com/kb/misc/wordpress/…Steve
This explains it better and might help - although it relates to self closing it shows how to work with the wp_autop() function: wordpress.stackexchange.com/questions/1/…Steve
Thisexplains more about removing filters which I hope might help:stackoverflow.com/questions/26836720/…Steve

2 Answers

2
votes

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 );
0
votes

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' );