function sajjadrogi_all_categories_shortcode($atts) {
$categories = get_categories();
if (empty($categories)) {
return 'No categories found.
';
}
$output = '';
foreach ($categories as $category) {
$output .= '- ' . $category->name . ' (' . $category->count . ')
';
}
$output .= '
';
return $output;
}
add_shortcode('all_categories', 'sajjadrogi_all_categories_shortcode');
How to Use the Shortcode:
Simply place the following shortcode in any post, page, or widget:
[all_categories]
Customization:
The list will show all categories as links, along with the number of posts in each category.
You can customize the CSS by targeting .sajjadrogi-category-list in your stylesheet.
0 Comments