Reputation: 5564
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
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
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