Header Assignments - Taxonomies

Hi,

I 've looked at https://theme.co/apex/forum/t/different-header-for-posts-of-certain-categories/58536/2 to assign headers by categories and I have three questions:

  1. Will the PHP code override the header builder assignments if they exist?
  2. How would you suggest to use it for a custom registered taxonomy called for example custom-category?
  3. How would you modify it to assign footers in the same way?

Thanks!

Hi Amir,

Thanks for reaching out.

  1. Yes, the main purpose of that filter is to override it, and then assigning.

  2. You could use it in anyway you want and on any taxonomy, the important part of that code is this

add_filter('cs_match_header_assignment', 'custom_search_header');

function custom_search_header($match) {
   
   /* your condition and ID matching here */

    return $match;
}

It’s up to you which condition you’ll add, like what category, taxonomy, and so on. Example


add_filter('cs_match_header_assignment', 'custom_search_header');

function custom_search_header($match) {

/* let's display the same header regardless of terms for custom registered custom-category */

    if ( is_tax('custom-category') ) {
        $match = 81;
    }

/* your custom registered custom-category, with news as term (eg. /custom-category/news/ ) */

    if ( is_tax('custom-category', 'news') ) {
        $match = 82;
    }

/* your custom registered custom-category, with technology as term (eg. /custom-category/technology/ ) */

    if ( is_tax('custom-category', 'technology') ) {
        $match = 83;
    }

/* you could also apply the same header for multiple custom registered taxonomy, like for Woocommerce product with the same term of video */

    if ( is_tax('custom-category', 'video') || is_tax('product-category', 'video') ) {
        $match = 84;
    }


    return $match;
}

All in all, the condition is up to you, and you could check other possible conditions that you could use from Wordpress documentation, example https://codex.wordpress.org/Function_Reference/is_tax

  1. It should be similar but with just different filter, like this
add_filter('cs_match_footer_assignment', 'custom_search_footer');

function custom_search_footer($match) {
   
   /* your condition and ID matching here */

    return $match;
}

Hope this helps

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