Site logo

Archived topic

Customize category page

5 replies · Started by Roger on July 6, 2019

Viewing posts 1–6 of 6

Hi, I'm trying to figure out how to customize the category page using the Header Element. I want to:

- add a featured image to each post category
- create a header element for the category page which uses the featured image with the category title and description for the page-hero

Would be grateful for help on how to achieve this in GP. Thanks!

Hi there,

WordPress doesn't allow featured images on archive/category pages so you will need to create a header element for each category and use the custom image option.

Using the {{post_title}} template tag would output the category name:
https://docs.generatepress.com/article/header-element-template-tags/

Then this should work for category description:
https://generatepress.com/forums/topic/add-custom_field-description-in-category-header/#post-375162

Let me know if this helps :)

Thanks Leo.

When I add Tom's function to create the shortcode into the child theme's functions.php file it gives me a fatal error. Any ideas on what I need to correct?

add_shortcode( 'term_description', 'tu_term_description' );
function tu_term_description() {
    ob_start();
    echo term_description( get_queried_object()->term_id', 'category' );
    return ob_get_clean();
}

Try this instead:

add_shortcode( 'term_description', 'tu_term_description' );
function tu_term_description() {
    ob_start();
    echo term_description( get_queried_object()->term_id, 'category' );
    return ob_get_clean();
}

Perfect, thanks. All working fine.

No problem :)

This archived topic is closed to new replies.