justjoe
justjoe

Reputation: 5564

How to check whether a particular widget is show or not in the sidebar?

i want to code something in my post template. So, is there any way to check whether a widget that i want to show will be shown in sidebar or not ?

Upvotes: 1

Views: 543

Answers (2)

Pankaj Kanani
Pankaj Kanani

Reputation: 137

You can add condition like this

<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div>
<?php endif; ?>

Upvotes: 0

stefanglase
stefanglase

Reputation: 10402

Have a look at the WordPress function is_active_widget(). It might be what you are looking for: https://developer.wordpress.org/reference/functions/is_active_widget/.

Upvotes: 2

Related Questions