How to List WordPress Categories

If you want to display a list of your post categories on your website without using the widgets on the WordPress dashboard, this tutorial is for you.

Listing All the Categories

To list all the categories, open the file for the page where you want to list the categories and paste the following line in:

<?php wp_list_categories('title_li='); ?>

Excluding Certain Categories from the List

To exclude certain categories from the list, add the following lines to the functions.php file:

// Exclude certain categories from the Category widget
function custom_category_widget($args) {
$exclude = "1,2"; // Category IDs to exclude
$args["exclude"] = $exclude;
return $args;

And then put the following lines in the file for the page where you want to display the categories:

<?php $cat_args['title_li'] = ''; wp_list_categories( apply_filters( 'widget_categories_args', $cat_args, $instance ) ); ?>