Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

the_category

Function Description:

Displays category list for a post in either HTML list or custom format.

Function Examples:

⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Basic usage: Display the categories of the current post
the_category();
// Display the categories of a specific post by passing post ID as a parameter
the_category( $post_id );
// Avoid duplicate categories by using the 'echo' parameter set to false
$categories = get_the_category();
if ( ! empty( $categories ) ) {
    echo '
    '; foreach( $categories as $category ) { echo '
  • ' . $category->name . '
  • '; } echo '
'; }