0
votes

I am working on a wordpress site (my first), where I want to use a specific sidebar for a specific page template. The sidebar is not the regular widget area, but a template (sidebar-2.php) that calls another template (boeking.php) of a form.

I used the default page.php and sidebar.php as a starting point, copied almost everything, and thus created a template for the page (reisbeschrijving.php) that calls sidebar-2 by using get_sidebar('2'). I also created a template sidebar-2.php:

It worked at first, but while I was working on another part of the website it stopped working all of a sudden. The page template works fine, but it doesn't load the sidebar-2, because the is_active_sidebar() returns false. However, I don't know why it returns false. When I call get_sidebar() (default) in reisbeschrijving.php, it does display sidebar.php, and is_active_sidebar() returns true. If I remove the if is_active_sidebar() clause, sidebar-2 displays just fine. both sidebar.php and sidebar-2.php are in the same folder (of the child theme).

Did I miss something? Should I register the new sidebar-2 template somewhere in the header or something? I know that this is the case for the custom dynamic sidebars with widget area's, but this is an altogether new template and I thought I wouldn't have to (I tried anyway, but to no avail). Any hints on why is_active_sidebar returns 'false' on my second sidebar is greatly appreciated.

1
You need to register your sidebar in your functions.php file. Look at register_sidebar() documentation.disinfor

1 Answers

0
votes

1st Register sidebar - functions.php

function my_custom_sidebar() {
    register_sidebar(
        array (
            'name' => __( 'Custom', 'your-theme-domain' ),
            'id' => 'custom-side-bar',
            'description' => __( 'Custom Sidebar', 'your-theme-domain' ),
            'before_widget' => '<div class="widget-content">',
            'after_widget' => "</div>",
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>',
        )
    );
}
add_action( 'widgets_init', 'my_custom_sidebar' );
  1. Put this code in template

    if ( is_active_sidebar( 'custom-side-bar' ) ) : dynamic_sidebar( 'custom-side-bar' ); endif;

This will work 100%