I have looked to see if there is a simple function that only returns the name of a category on a post. I am looking to output it as a subheading for a list of posts but do not want it as a link and the the_category(); function only returns a link.

I also don't want it as a list. Any thoughts on how I can just get the "slug" of the category?

2 Answers 2


What you are looking for is get_the_category(). Retrieve a list of the categories, and then run a loop and only output their names:

$categories = get_the_category();
if ( ! empty( $categories ) ) {
    foreach( $categories as $category ){
        echo esc_html( $category->name );   

This function returns an array of WP_Term objects. You can check the provided link for a list of available methods.


You can use get_the_terms with any taxonomy and output without the link like this :

$terms = get_the_terms( get_the_ID(), 'category' );
if ( $terms && ! is_wp_error( $terms ) ) : 
$cats = array();
foreach ( $terms as $term ) {
    $cats[] = $term->name;
$cats = join( ', ', $cats );

echo $cats;



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.