Retrieves category parents with separator.
Parameters
$category_idintrequired- Category ID.
$linkbooloptional- Whether to format with link.
Default:
false $separatorstringoptional- How to separate categories. Default
'/'.Default:
'/' $nicenamebooloptional- Whether to use nice name for display.
Default:
false $deprecatedarrayoptional- Not used.
Default:
array()
Source
function get_category_parents( $category_id, $link = false, $separator = '/', $nicename = false, $deprecated = array() ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '4.8.0' );
}
$format = $nicename ? 'slug' : 'name';
$args = array(
'separator' => $separator,
'link' => $link,
'format' => $format,
);
return get_term_parents_list( $category_id, 'category', $args );
}
Note that
$nicenamereally means theslug. So if the$nicenameparameter is set totrue, the function will use the termslugfor display, and using the default value offalsewill use the human readable display name of the term.May be confusing at first, as some of us may think human readable names are nicer than slugs.
Basic Example
Returns the parent categories of the current category with links separated by ‘»’
will output: