2

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.

2
  • Try to call your sidebar like this <?php get_sidebar('primary'); ?> instead of this <?php include('sidebar-primary.php'); ?>. See if that works.
    – Rishabh
    Sep 20, 2016 at 10:47
  • Thanx for your reply. I tried, it doesn't work. I tried also with <?php dynamic_sidebar( 'primary' ); ?> but nothing shows. I am going out of my mind.
    – Nancy
    Sep 20, 2016 at 10:50

1 Answer 1

2

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.

3
  • yes, I closed the div, i edited the code here now. I tried your solution, but it still doesn't show anything.
    – Nancy
    Sep 20, 2016 at 11:12
  • Thats strange! This is how I use to make my sidebars and it always worked well. Then may be problem is not the code, its something else. Try to disable your all plugins then try to add any default widget in sidebar and see it that works.
    – Rishabh
    Sep 20, 2016 at 11:20
  • Found solution! see the updated answer
    – Rishabh
    Sep 20, 2016 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.