Site logo

Archived topic

Display custom sidebar on category pages

1 reply · Started by Hilton on December 4, 2019

Viewing posts 1–2 of 2

Hi,

I used the code below to register a new sidebar and display into category pages. The sidebar was registered, but I can't see it in the categories of the site.

if ( function_exists('register_sidebar') ) {
	register_sidebar(array(
		'name' => 'Categorias',
		'id' => 'categorias-sidebar',
		'description' => 'Sidebar for categories',
		'before_widget' => '<li id="%1$s">',
		'after_widget' => '</li>',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	));
}

add_filter( 'generate_sidebar_layout', function( $layout ) {
    // If we are on a category, set the sidebar
    if ( is_category() ) {
        return 'categorias-sidebar';
    }

    // Or else, set the regular layout
    return $layout;
 } );
This archived topic is closed to new replies.