Title: get_the_category_list
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_the_category_list( string $separator = '', string $parents = '', int|false $post_id = false ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#wp--skip-link--target)

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

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#description)󠁿

Generally used for quick, delimited (e.g. comma-separated) lists of categories, 
as part of a post entry meta.

For a more powerful, list-based function, see [wp_list_categories()](https://developer.wordpress.org/reference/functions/wp_list_categories/).

### 󠀁[See also](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#see-also)󠁿

 * [wp_list_categories()](https://developer.wordpress.org/reference/functions/wp_list_categories/)

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#parameters)󠁿

 `$separator`stringoptional

Separator between the categories. By default, the links are placed in an unordered
list. An empty string will result in the default behavior.

Default:`''`

`$parents`stringoptional

How to display the parents. Accepts `'multiple'`, `'single'`, or empty.

Default:`''`

`$post_id`int|falseoptional

ID of the post to retrieve categories for. Defaults to the current post.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#return)󠁿

 string Category list for a post.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#source)󠁿

    ```php
    function get_the_category_list( $separator = '', $parents = '', $post_id = false ) {
    	global $wp_rewrite;

    	if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) {
    		/** This filter is documented in wp-includes/category-template.php */
    		return apply_filters( 'the_category', '', $separator, $parents );
    	}

    	/**
    	 * Filters the categories before building the category list.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param WP_Term[] $categories An array of the post's categories.
    	 * @param int|false $post_id    ID of the post to retrieve categories for.
    	 *                              When `false`, defaults to the current post in the loop.
    	 */
    	$categories = apply_filters( 'the_category_list', get_the_category( $post_id ), $post_id );

    	if ( empty( $categories ) ) {
    		/** This filter is documented in wp-includes/category-template.php */
    		return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents );
    	}

    	$rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';

    	$thelist = '';
    	if ( '' === $separator ) {
    		$thelist .= '<ul class="post-categories">';
    		foreach ( $categories as $category ) {
    			$thelist .= "\n\t<li>";
    			switch ( strtolower( $parents ) ) {
    				case 'multiple':
    					if ( $category->parent ) {
    						$thelist .= get_category_parents( $category->parent, true, $separator );
    					}
    					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name . '</a></li>';
    					break;
    				case 'single':
    					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '"  ' . $rel . '>';
    					if ( $category->parent ) {
    						$thelist .= get_category_parents( $category->parent, false, $separator );
    					}
    					$thelist .= $category->name . '</a></li>';
    					break;
    				case '':
    				default:
    					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name . '</a></li>';
    			}
    		}
    		$thelist .= '</ul>';
    	} else {
    		$i = 0;
    		foreach ( $categories as $category ) {
    			if ( 0 < $i ) {
    				$thelist .= $separator;
    			}
    			switch ( strtolower( $parents ) ) {
    				case 'multiple':
    					if ( $category->parent ) {
    						$thelist .= get_category_parents( $category->parent, true, $separator );
    					}
    					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name . '</a>';
    					break;
    				case 'single':
    					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>';
    					if ( $category->parent ) {
    						$thelist .= get_category_parents( $category->parent, false, $separator );
    					}
    					$thelist .= "$category->name</a>";
    					break;
    				case '':
    				default:
    					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name . '</a>';
    			}
    			++$i;
    		}
    	}

    	/**
    	 * Filters the category or list of categories.
    	 *
    	 * @since 1.2.0
    	 *
    	 * @param string $thelist   List of categories for the current post.
    	 * @param string $separator Separator used between the categories.
    	 * @param string $parents   How to display the category parents. Accepts 'multiple',
    	 *                          'single', or empty.
    	 */
    	return apply_filters( 'the_category', $thelist, $separator, $parents );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/category-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/category-template.php#L141)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/category-template.php#L141-L231)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#hooks)󠁿

 [apply_filters( ‘the_category’, string $thelist, string $separator, string $parents )](https://developer.wordpress.org/reference/hooks/the_category/)

Filters the category or list of categories.

 [apply_filters( ‘the_category_list’, WP_Term[] $categories, int|false $post_id )](https://developer.wordpress.org/reference/hooks/the_category_list/)

Filters the categories before building the category list.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#related)󠁿

| Uses | Description | 
| [get_the_category()](https://developer.wordpress.org/reference/functions/get_the_category/)`wp-includes/category-template.php` |

Retrieves post categories.

  | 
| [get_category_parents()](https://developer.wordpress.org/reference/functions/get_category_parents/)`wp-includes/category-template.php` |

Retrieves category parents with separator.

  | 
| [get_category_link()](https://developer.wordpress.org/reference/functions/get_category_link/)`wp-includes/category-template.php` |

Retrieves category link URL.

  | 
| [is_object_in_taxonomy()](https://developer.wordpress.org/reference/functions/is_object_in_taxonomy/)`wp-includes/taxonomy.php` |

Determines if the given object type is associated with the given taxonomy.

  | 
| [get_post_type()](https://developer.wordpress.org/reference/functions/get_post_type/)`wp-includes/post.php` |

Retrieves the post type of the current post or of a given post.

  | 
| [WP_Rewrite::using_permalinks()](https://developer.wordpress.org/reference/classes/wp_rewrite/using_permalinks/)`wp-includes/class-wp-rewrite.php` |

Determines whether permalinks are being used.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [esc_url()](https://developer.wordpress.org/reference/functions/esc_url/)`wp-includes/formatting.php` |

Checks and cleans a URL.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#)

| Used by | Description | 
| [the_category()](https://developer.wordpress.org/reference/functions/the_category/)`wp-includes/category-template.php` |

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

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.5.1](https://developer.wordpress.org/reference/since/1.5.1/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#comment-content-502)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_the_category_list/#comment-502)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_category_list%2F%23comment-502)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_category_list%2F%23comment-502)
 4.  **Display as List Items**
      By leaving the `$separator` value empty, it will generate
     an unordered list instead, complete with classes.
 5.      ```php
         <?php echo get_the_category_list(); ?>
         ```
     
 6.  Result:
 7.      ```php
         <ul class="post-categories">
         	<li>
         		<a href="http://myblog.com/category/business&quot; title="View all posts in Business" rel="category tag">Business</a>
         	</li>
         </ul>
         ```
     
 8.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_category_list%2F%3Freplytocom%3D502%23feedback-editor-502)
 9.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/get_the_category_list/?output_format=md#comment-content-501)
 10.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_the_category_list/#comment-501)
 11. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_category_list%2F%23comment-501)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_category_list%2F%23comment-501)
 12. **Implementation in WordPress default Twenty Eleven theme**
      In `content-single.
     php`:
 13.     ```php
         <?php
         /* translators: used between list items, there is a space after the comma */
         $categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) );
     
         /* translators: used between list items, there is a space after the comma */
         $tag_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) );
         if ( '' != $tag_list ) {
         	$utility_text = __( 'This entry was posted in %1$s and tagged %2$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
         } elseif ( '' != $categories_list ) {
         	$utility_text = __( 'This entry was posted in %1$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
         } else {
         	$utility_text = __( 'This entry was posted by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
         }
     
         printf(
         	$utility_text,
         	$categories_list,
         	$tag_list,
         	esc_url( get_permalink() ),
         	the_title_attribute( 'echo=0' ),
         	get_the_author(),
         	esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) )
         );
         ?>
         ```
     
 14.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_category_list%2F%3Freplytocom%3D501%23feedback-editor-501)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_category_list%2F)
before being able to contribute a note or feedback.