1

I'm using DIVI theme and have created a custom category layout. However, I can't seem to find a way to add the category description to the layout. DIVI doesn't provide any answers, and I've searched here as well. Can I use some tags to get it?

The code below almost works - I do get the text, but not linebreaks, even though they are present if I do a echo '<pre>'; print_r($cat); echo '</pre>';

add_shortcode('cat_desc', 'cat_desc_shortcode');
function cat_desc_shortcode() {
    
    global $wp_query;
    $cat = $wp_query->get_queried_object();
        
    if( $cat == null ) return;

    $output = '<div class="page-description"> '.$cat->description.' </div> ';
    return $output;
}

Thanks

Dyvel
  • 847
  • 1
  • 8
  • 20

1 Answers1

2

Got it working now. For others in the same situation, add this code to your functions.php file in your (child) theme.

add_shortcode('cat_desc', 'cat_desc_shortcode');
function cat_desc_shortcode() {
    
    global $wp_query;
    $cat = $wp_query->get_queried_object();
    
    if( $cat == null ) return;

    $output = nl2br($cat->description);
    return $output;
}

Then use the shortcode [cat_desc] in your layout, where you would like the category description to appear. This at least works for me.

Dyvel
  • 847
  • 1
  • 8
  • 20
  • Thank you! This works for me. I'm very new to wp/woocommerce so I followed this tutorial to create a divi-child theme https://developer.wordpress.org/themes/advanced-topics/child-themes/#what-is-a-child-theme - and tried to just add your solution to the child theme. But when I activiated the child theme, the divi theme builder displayed a very wacky layout. So in the end I just appended your addition above to the functions.php of the Divi theme to solve my problem for now. – wr200m Jul 30 '22 at 20:55