• I’ve researched a lot about doing this, and I was only able to figure out how to put all of the categories into an array.

    I have this currently:
    $category = get_the_category();
    echo $category[0]->cat_name;

    Then I guess I can just change 0 to 1, 2, 3, etc, to get the different categories. But what if I just want to echo the current category for that page? (from outside the loop if that’s possible).

    Any suggestions?

    Edit: P.S. I’ve also been trying other stuff like the_category(‘, ‘); but they they seem to echo a category link or the path to the category.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Thread Starter samiejg

    (@samiejg)

    Thanks for the quick response. I seen those pages before, but they didn’t seem to be working for me (I think because I was outside the loop | or it wants me to specify a category rather than grabbing the existing one).

    I’ll try having a look over them again to see if there’s anything I missed.

    Thread Starter samiejg

    (@samiejg)

    I don’t think these links are relevant unfortunately 🙁

    The “single_cat_title” one you posted says it will only work on category and tag pages.

    The “get_cat_name” one says “Retrieve the name of a category from its ID”, but that’s my whole issue that I’m trying get the category without having to use an ID.

    The reason for this is because I’m trying to get my <title> tag to dynamically show the category for the actual post. I’m also planning on using it for a few more things too.

    Any more suggestions?

    Moderator keesiemeijer

    (@keesiemeijer)

    On what page are you trying this? And what do you mean with “the current category” if you’re not on a category archive page?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How do you echo a category name?’ is closed to new replies.