dynamic sidebar not showing anything

I made custom sidebar and put YITH WooCommerce Ajax Product Filter widget inside to show filter by color. I did the following steps:

  1. In my functions.php I registered sidebar like this:

     add_action( 'widgets_init', 'my_register_sidebars' );
        function my_register_sidebars() {
        /* Register the 'primary' sidebar. */
        register_sidebar(
            array(
                'id'            => 'primary',
                'name'          => __( 'Primary Sidebar' ),
                'description'   => __( 'A short description of the sidebar.' ),
                'before_widget' => '<div id="%1$s" class="widget %2$s">',
                'after_widget'  => '</div>',
                'before_title'  => '<h3 class="widget-title">',
                'after_title'   => '</h3>',
            )
        );
    
    }
    
  2. I made sidebar-primary.php like this:

    <div id="sidebar-primary" class="sidebar">
    <?php dynamic_sidebar( 'primary'); ?></div>
    
  3. Added widget to my sidebar

  4. On my page where I need the content of sidebar to show, I included sidebar-primary.php like this:

    <?php include('sidebar-primary.php'); ?>

But nothing is showing. Any suggestions? Maybe I am doing something wrong without even realizing it. Thanx.

1 Answer
1

In your functions.php file try register sidebar without putting in function like this

register_sidebar(array(    //try not to enclose this in function
'id'            => 'primary',
        'name'          => 'Primary Sidebar',
        'description'   => 'A short description of the sidebar.',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
));

And make call on page like this

<?php get_sidebar('primary'); ?>

And in your sidebar-primary.php I am assuming you have closed the div. In your code you haven’t show closed div of this file.

UPDATE

Try the above method and change the ID name of sidebar from functions.php You can’t use same name for ID and sidebar php file (sidebar_primary.php).

So you need to change Id name from functions.php file and as well as from sidebar_primary.php. like

<?php dynamic_sidebar( 'primary'); ?></div>

In above code primary is id and you need to rename it.

Leave a Comment