Show active sidebar in Wordpress

2019-08-15 03:21发布

So I'm trying to not show a side bar if it there are no widgets to show

when I use the is_active_sidebar() function it always returns false and the if statement doesn't work and when I try to use the is_dynamic_sidebar() function it always returns true.

I have the widget logic plugin installed so some of the widgets show up on a page and some pages don't have a widget.

This is my code:

        <div class="row main-row">
        <?php if (is_dynamic_sidebar('left_bar')) { ?>
            <div class="col-md-3 left-sidebar">
                <?php
                dynamic_sidebar('left_bar');
                ?>
            </div>

            <div class="col-md-9 main-content">
                <?php the_content('Read More'); ?>
            </div>
        <?php } else { ?>
            <div class="col-md-12 main-content">
                <?php the_content('Read More'); ?>
            </div>
        <?php } ?>
    </div>

Any Ideas on what should I do?

2条回答
虎瘦雄心在
2楼-- · 2019-08-15 03:53

You have used wrong function for checking active sidebar try this

if ( is_active_sidebar( 'left_bar' ) )
dynamic_sidebar( 'left_bar' );
查看更多
我想做一个坏孩纸
3楼-- · 2019-08-15 04:07

try this one, it is different way of using sidebar

[1] put your all "left_bar"(sidebar) code in a new file named "sidebar-left_bar"

[2] save it with header.php, function.php and all files

[3] now just use <?php get_sidebar( 'left_bar' ); ?> where you want to use

Thanks

查看更多
登录 后发表回答