Search code examples
phpwordpresswoocommerceshortcode

Woocommerce category description using shortcode


I want to replace the Woocommerce category description on pages using a shortcode.

With the shortcode I want to dynamically display custom featured image and description for current category.

Here is some code I found from searching here and Google. This code seemed to work but also affected single product pages.

Can someone tell me what is wrong with this please ?

add_filter('woocommerce_short_description', function ($description) {
    if (! is_product_category()) { return; }   
    return do_shortcode('[porto_block id="510079"]');
});

Solution

  • Use the following conditions to make sure it only works on category pages.

    add_filter('woocommerce_short_description', function ($description) {
        if ( is_product_category() && !is_single() && !is_product()) {    
            return do_shortcode('[porto_block id="510079"]');
        }else{
            return $description;
        }
    });