Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get category parents


Returns a list of the parents of a category, including the category, in hierarchical order.


 <?php get_category_parents$id$link$separator$nicename$visited ); ?> 


(integer) (required) Category ID.
Default: None
(boolean) (optional) Whether to create a link to each category displayed.
Default: false
(string) (optional) What to separate each category by.
Default: '/'
(boolean) (optional) Whether to use nice name for display. If set to true, the category slug will be used instead of the category name.
Default: false
(boolean) (optional) Already linked-to categories. This parameter is used internally by the function, which makes recursive calls to itself, to prevent duplicates in the returned list.
Default: array()

Return Values

The categories, separated by $separator. WP_Error on failure.


Returns the parent categories of the current category with links separated by '»'

<?php echo get_category_parents( $cat, true, ' &raquo; ' ); ?>

will output:

Internet » Blogging » WordPress »

Change Log

Source File

get_category_parents() is located in wp-includes/category-template.php


See also index of Function Reference and index of Template Tags.