Header assigned to a Post category

Hi,

Is there any way of assigning an header to a Post Category, rather than having to assign it to individual posts manually?

many thanks

Alex

Hi Alex,

The method that I want to introduce is considered as customization and outside of our support scope. I will do my best to give you the data to work but the implementation will be on your shoulders.

Please kindly follow the steps below:

  1. Go to Pro > Header and click on the Edit button of the header in question.
  2. Write down the ID at the very end of your browser address bar while you are in the editing screen of the header.
  3. Go to WordPress Dashboard > Posts > Categories.
  4. Write down the Slug of the category that you want the posts inside that category to have the header in question.
  5. Install the Child Theme. (Skip this step if you already have a child theme)
  6. Add the code below to the very end of functions.php file of your child theme:
function custom_header_assignment( $match ) {
  if ( is_single() ) {
    if ( in_category( 'slug' ) ) { 
      $match = 1234; // the post ID for your header      
    }
  }
  return $match;
}
add_filter( 'cs_match_header_assignment', 'custom_header_assignment' );
  1. Replace slug with the slug you wrote down in step 4.
  2. Replace 1234 with the header ID you wrote down in step 2.

The given code checks to see if the current page is single (it is a post) and checks if it is in the category in question. Then assigns the Header ID to cs_match_header_assignment hook which is the one used to assign headers.

Thank you.

Thank you do much - worked a treat

As usual support over and beyond.

Stay safe

Alex

You’re welcome!
We’re glad @Christopher were able to help you out.

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