Different header for posts of certain categories

Hello,

Is it possible at all to assign a different header based on the category the post is in? or would i have to select them all individually?

thanks

Hi @SophiePeirce,

You need to select them all individually, but you can assign it using a custom code.

You can try adding the code below in your child theme’s functions.php file.

add_filter('cs_match_header_assignment', 'custom_search_header');
function custom_search_header($match) {
    if ( in_category('blog') ) {
        $match = 81; // the post ID for your header
    }
    return $match;
}

Where blog is the category name and 81 is the header ID

For more information kindly refer to the links below

https://developer.wordpress.org/reference/functions/in_category/

Kindly note that since this is a custom code that changes the default behavior/display of the theme, you will be responsible to maintain or update the code in case you require further changes or if the code stops working in future updates.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.