Support » Themes and Templates » Adding Post Category To H1 Title

  • Hi Guys (& Ladies of course);-)

    I’m having a problem trying to add post category to the H1 title, I have managed to butcher my theme so that the home page has the blog title as a H1 tag in the header, but the single post now removes the H1 from the title in the header & instead adds it to the post title.

    But what I’d like to do now is keep the H1 blog title on all pages including home page, but I’d like to amend the title with the addition of the post category, as follows;

    currently shows “Top Rated Gadgets” on all pages.

    would like it to show “Top Rated (category name)” when viewing a single post.
    So if the category of the post was Asus Laptops it would show “Top Rated Asus Laptops” instead of the usual “Top Rated Gadgets”
    The closest I have got to it so far is with <?php the_category(', '); ?> but this returns a hyperlink ! Is there any method I can use that will simply return the category name as plain text..?
    I have looked through the codex several times but cannot seem to find anything that refers to this particular issue..?

    Any help would be grately appreciated

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • instead of:
    <?php the_category(', '); ?>

    try:
    <?php $cats = get_the_category(); $sep = ''; foreach($cats as $cat) { echo $sep.$cat->cat_name; $sep = ', '; } ?>

    Wow that’s great, worked perfectly !

    Thanks a million

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding Post Category To H1 Title’ is closed to new replies.