Title: get_category_parents
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_category_parents( int $category_id, bool $link = false, string $separator, bool $nicename = false, array $deprecated = array() ): string|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

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

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

Retrieves category parents with separator.

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

 `$category_id`intrequired

Category ID.

`$link`booloptional

Whether to format with link.

Default:`false`

`$separator`stringoptional

How to separate categories. Default `'/'`.

`$nicename`booloptional

Whether to use nice name for display.

Default:`false`

`$deprecated`arrayoptional

Not used.

Default:`array()`

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

 string|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) 
A list of category parents on success, [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
on failure.

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

    ```php
    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 );
    }
    ```

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

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

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

Retrieves term parents with separator.

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

Marks a function argument as deprecated and inform when it has been used.

  |

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

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

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

Retrieves the full permalink for the current post or post ID.

  |

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

| Version | Description | 
| [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | The `$visited` parameter was deprecated and renamed to `$deprecated`. | 
| [1.2.0](https://developer.wordpress.org/reference/since/1.2.0/) | Introduced. |

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

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/get_category_parents/?output_format=md#comment-content-5982)
 2.    [Bence Szalai](https://profiles.wordpress.org/grapestain/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/get_category_parents/#comment-5982)
 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_category_parents%2F%23comment-5982)
     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_category_parents%2F%23comment-5982)
 4.  Note that `$nicename` really means the `slug`. So if the `$nicename` parameter
     is set to `true`, the function will use the term `slug` for display, and using
     the default value of `false` will use the human readable display name of the term.
 5.  May be confusing at first, as some of us may think human readable names are nicer
     than slugs.
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_category_parents%2F%3Freplytocom%3D5982%23feedback-editor-5982)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/get_category_parents/?output_format=md#comment-content-1119)
 8.    [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/get_category_parents/#comment-1119)
 9.  [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_category_parents%2F%23comment-1119)
     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_category_parents%2F%23comment-1119)
 10. **Basic Example**
 11. Returns the parent categories of the current category with links separated by ‘»’
 12.     ```php
         <?php echo get_category_parents( $cat, true, ' &raquo; ' ); ?>
         ```
     
 13. will output:
 14.     ```php
         Internet » Blogging » WordPress » 
         ```
     
 15.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_category_parents%2F%3Freplytocom%3D1119%23feedback-editor-1119)

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