Archived topic
Hook - Category Name
3 replies · Started by Andy on June 11, 2021
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.
Hi Andy,
Have you tried using the dynamic element in GPP 2.0?
https://docs.generatepress.com/article/dynamic-data/
Thank you, worked like a charm
No problem :)