WordPress Shortcode to Get Total Number of Categories

Srivishnu Ramakrishnan
Srivishnu Ramakrishnan
Engineer & Web Creator
LinkedInTwitter

Here's a shortcode to get the total number of categories in WordPress:

Shortcode:[total_categories]

Code for the shortcode

php
//Total Categories
function total_categories_count() {
    $categories = get_categories();
    return count($categories);
}
add_shortcode('total_categories', 'total_categories_count');

Wherever you want to display the total number of categories, you can simply use the [total_categories] shortcode.

How to add this code to your WordPress site

How to Add PHP Code to WordPress