Remove link to category archive in posts, but keep the text (5 posts)

  1. richardhenry
    Posted 9 years ago #

    I'm currently developing a theme for WordPress, and want to be able to show on posts 'This was posted on DATE in CATEGORY.'

    The CATEGORY part is the issue here.

    I can display the current category using the code:

    <?php the_category(', ') ?>

    ...but this not only displays this category, but makes the text linkable so the viewer can see more posts in the same category.

    Is there any way to show just plain text the category name, without having this as linkable text?

  2. moshu
    Posted 9 years ago #

    It seems you missed this while searching for an answer:

  3. richardhenry
    Posted 9 years ago #

    So I did, very sorry. Thanks for your reply!

  4. richardhenry
    Posted 9 years ago #

    P.S. For anyone who can't be bothered reading all that, simply insert:

    <?php foreach((get_the_category()) as $cat) { echo $cat->cat_name . ' '; } ?>

    ...anywhere in The Loop to display the category of the current post.

  5. godofcomics
    Posted 8 years ago #

    I needed the Category ID only, in text form [non-link]. So, if that is what you are also looking for, here is the code I found and tested: [it works].

    <?php foreach((get_the_category()) as $cat) { echo $cat->cat_ID . ' '; } ?>

    It displays only the cat id (number) instead of the name.

Topic Closed

This topic has been closed to new replies.

About this Topic