WordPress category list description

WordPress has two functions that you can use to create links to a series or articles sorted by tag (cloud style with wp_tag_cloud ) or category (hierarchical style via wp_list_categories)

add a description to your category list using simple walker via wonderful stackexchange threads providing wordpress category list shortcode and walker to add description to category list

function waveCategories() {
    $list = wp_list_categories( array(
        'taxonomy'   => 'category',
        'hide_empty' => 0,
        'echo'       => '',
        'title_li'   => '', 'walker' => new class extends Walker_Category
        {
            public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 )
            {
                // Let's use the output from the parent's start_el method
                $output .= parent::start_el( $output, $category, $depth, $args, $id );

                // Append the category description:
                $desc = $category->description;
                $output .= ( $desc ) ? sprintf( '<span>%s</span>', esc_html( $desc ) ) : '';
            }
        }
        // other args here
    ) );

    return "<ul>$list</ul>";

}

add_shortcode("waveCategories", "waveCategories");
To top