How to include category name of single post in page title (3 posts)

  1. MrFlora
    Posted 10 years ago #

    Anyone know what I can use to echo just the name of a single post's category in its page title in single post view? I've tried putting in the_category() but it gives the category to me as a link (with tags before and after it). I;m just looking to call up the category name from outside the loop.

    Any suggestions?


  2. MrFlora
    Posted 10 years ago #


  3. Kafkaesqui

    Posted 10 years ago #

    Couple ways:

    1. http://wordpress.org/support/topic/34542#post-195689

    2. More preferred way, place this at the top of your header (usually header.php) template:

    <?php $category = get_the_category(); ?>

    Then in your <title> element, something like the following (exact placement in the title is up to you):

    <?php if(is_single()) { echo echo $category[0]->cat_name; } ?>

    If #2 doesn't work, let me know. There's a way to duplicate what get_the_category() is doing for us here with the post's data but even more globally.

Topic Closed

This topic has been closed to new replies.

About this Topic