Site logo

Archived topic

Hook - Category Name

3 replies · Started by Andy on June 11, 2021

Viewing posts 1–4 of 4

Hi,
I'm using the generate_before_entry_title hook to try to display the category associated with a post on the blog archive page.
I've tried using the template tag {{post_terms.category}} but I don't think these work inside Hooks. However, I also tried the following the PHP with the 'Execute PHP' option enabled but this hasnt worked either, see code below:

<?php
      $categories = get_the_category('1');
      foreach($categories as $category){
      echo $category->name;
    }
?>

I want it to display above the post title, I can see the H3 tag being generated but its empty.

Any help much appreciated.

Thank you, worked like a charm

No problem :)

This archived topic is closed to new replies.