How to get a customized sidebar on the post archive page (Ethos)

I have created a special sidebar (in the widget area) that I want to display on my yearly post archive. I’ve found the wp-index.php and placed it in my child-theme folder. But I can’t figure out how to load my special sidebar there.

Best Regards
Bengt

Hi Bengt,

Thank you for reaching out to us. To assign a custom sidebar to your archive pages, assuming that the child theme is set up, please add the following code in your child theme’s functions.php file

// =============================================================================
// Assign sidebar to custom post archives
// =============================================================================
add_filter( 'ups_sidebar', 'add_cpt_sidebar' );
function add_cpt_sidebar($sidebar){
  if ( is_archive()) {
    return 'ups-sidebar-my-sidebar';
  }
  return $sidebar;
}
// =============================================================================

Don’t forget replace ups-sidebar-my-sidebar with the actual ID of your custom sidebar as shown below:

Hope this helps!

It worked perfect!
Thanks Nabeel

Best Regards
Bengt

We are delighted to assist you with this.

Cheers!

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