Solution: the_category() always generates links. Use foreach and get_the_category to get plain text.
EN

How to get category name without a link in WordPress (get_the_category)

5.00 /5 - (30 votes )
Last verified: May 1, 2026
2min read
Tutorial
500+ WP projects
Full-stack developer

The standard WordPress function the_category() is great, but it has one flaw: it always generates HTML links (<a href="...">...</a>) to the archive page. What if you’re building a custom layout (like a portfolio card or slider) where the category should be plain text, not a clickable element?

Learn more about professional WordPress development at WPPoland. The solution is to use get_the_category(), which returns an array of objects instead of ready-made HTML.

#Code (snippet)

Here’s a ready-to-use snippet you can paste into your single.php or content.php:

<?php
// Get all categories assigned to the current post
$categories = get_the_category();

if ( ! empty( $categories ) ) {
    // Display the name of the first category found
    echo esc_html( $categories[0]->name );
}
?>

#Displaying a comma-Separated list

If your post has multiple categories and you want to list them as comma-separated text:

<?php
$categories = get_the_category();
$output     = array();

if ( ! empty( $categories ) ) {
    foreach ( $categories as $category ) {
        // Add name to the array
        $output[] = esc_html( $category->name );
    }
    // Join the array into a string with a separator
    echo implode( ', ', $output );
}
?>

#Why get_the_category()?

This function gives you access to the full category object. Besides the name (->name), you can extract:

  • ->slug (useful for CSS classes, e.g., <span class="cat-<?php echo $cat->slug; ?>">)
  • ->term_id (category ID)
  • ->description (category description)
  • ->count (number of posts in this category)

#Practical application

A common use case is styling labels on blog cards.

// Inside the WordPress loop
$cats = get_the_category();
$first_cat = !empty($cats) ? $cats[0] : null;

if ($first_cat) : ?>
    <span class="badge badge-<?php echo esc_attr($first_cat->slug); ?>">
        <?php echo esc_html($first_cat->name); ?>
    </span>
<?php endif; ?>

This way, if you have a category “News”, you’ll get the class .badge-news, which you can easily color in CSS. This level of control is something the_category() simply doesn’t offer.

Next step

Turn the article into an actual implementation

This block strengthens internal linking and gives readers the most relevant next move instead of leaving them at a dead end.

Want this implemented on your site?

If you want to convert the article into a working site improvement, redesign, or build plan, I can define the scope and implement it.

Related cluster

Explore other WordPress services and knowledge base

Strengthen your business with professional technical support in key areas of the WordPress ecosystem.

Article FAQ

Frequently Asked Questions

Practical answers to apply the topic in real execution.

SEO-ready GEO-ready AEO-ready 3 Q&A
Why not use the_category() if I only need text?
Because the_category() prints ready-made HTML links. If you need plain text for a badge, slider or custom layout, get_the_category() gives you direct access to the category object.
How do I display only the first category name?
Fetch the category array with get_the_category(), check it is not empty, then print the first item's name with proper escaping.
How can I output several category names without links?
Loop through the category objects, collect the names into an array and join them with implode() so you control the separator and avoid anchor tags.

Need an FAQ tailored to your industry and market? We can build one aligned with your business goals.

Let’s discuss

Related Articles

How to retrieve and display a list of posts from a specific category in WordPress? Learn WP_Query, get_posts and custom loops. Code examples and optimization.
wordpress

Extracting post lists from categories in WordPress – Developer guide

How to retrieve and display a list of posts from a specific category in WordPress? Learn WP_Query, get_posts and custom loops. Code examples and optimization.

How to start as a WordPress developer in 2026. Local environment, theme and plugin development, REST API and headless paths, security and Core Web Vitals. A practitioner playbook that does not waste your first month.
wordpress

WordPress development tutorial: a comprehensive guide for beginners in 2026

How to start as a WordPress developer in 2026. Local environment, theme and plugin development, REST API and headless paths, security and Core Web Vitals. A practitioner playbook that does not waste your first month.

Complete guide to WordPress Multisite for enterprise deployments. Learn architecture patterns, scaling to 1000+ sites, security hardening, domain mapping, user management, and cost optimization for franchise, university, and government networks.
wordpress

WordPress Multisite for Enterprise: Architecture, Scaling & Best Practices

Complete guide to WordPress Multisite for enterprise deployments. Learn architecture patterns, scaling to 1000+ sites, security hardening, domain mapping, user management, and cost optimization for franchise, university, and government networks.